From d42199299e8160519744fef1f5d50b675b0360f1 Mon Sep 17 00:00:00 2001 From: nourmhassan Date: Mon, 19 Feb 2018 18:56:35 -0800 Subject: [PATCH] nour hassan --- src/project-1.js | 77 +++++++++++++++++++++++++++++++++++++++++++++++- src/project-2.js | 71 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 1 deletion(-) diff --git a/src/project-1.js b/src/project-1.js index dc26cfb..502c626 100644 --- a/src/project-1.js +++ b/src/project-1.js @@ -1,6 +1,8 @@ // Do not change any of the funcxtion names const multiplyByTen = (num) => { + return num * 10; + // return num after multiplying it by ten // code here }; @@ -8,110 +10,172 @@ const multiplyByTen = (num) => { const subtractFive = (num) => { // return num after subtracting five // code here + return num - 5; }; const areSameLength = (str1, str2) => { // return true if the two strings have the same length // otherwise return false // code here +if (str1.length === str2.length) { + return true; +} else { + return false; +} }; const areEqual = (x, y) => { // return true if x and y are the same // otherwise return false // code here +if(x===y){ +return true; +}else{ +return false; +} }; const lessThanNinety = (num) => { // return true if num is less than ninety // otherwise return false // code here +if(num<90){ +return true; +}else{ +return false; +} }; const greaterThanFifty = (num) => { // return true if num is greater than fifty // otherwise return false // code here +if(num>50){ +return true; +}else{ +return false; +} }; const add = (x, y) => { // add x and y together and return the value // code here + var result = x+y; + return result; }; const subtract = (x, y) => { // subtract y from x and return the value // code here +var result = x-y; +return result; }; const divide = (x, y) => { // divide x by y and return the value // code here +var result = x/y; +return result; }; const multiply = (x, y) => { // multiply x by y and return the value // code here +var result = x*y; +return result; }; const getRemainder = (x, y) => { // return the remainder from dividing x by y // code here +var result = x%y; +return result; }; const isEven = (num) => { // return true if num is even // otherwise return false // code here +if(num%2 ==0){ +return true; +}else{ +return false; +} }; const isOdd = (num) => { // return true if num is odd // otherwise return false // code here +if(num%2 !=0){ +return true; +}else{ +return false; +} }; const square = (num) => { // square num and return the new value // code here +var result = Math.pow(num,2); +return result; }; const cube = (num) => { // cube num and return the new value // code here +var result = Math.pow(num,3); +return result; + }; const raiseToPower = (num, exponent) => { // raise num to whatever power is passed in as exponent // code here +var result = Math.pow(num,exponent); +return result; + }; const roundNumber = (num) => { // round num and return it // code here +var result = Math.round(num) +return result; }; const roundUp = (num) => { // round num up and return it // code here +var result = Math.ceil(num) +return result; + }; const addExclamationPoint = (str) => { // add an exclamation point to the end of str and return the new string // 'hello world' -> 'hello world!' // code here +var result = str + '!'; +return result; }; const combineNames = (firstName, lastName) => { // return firstName and lastName combined as one string and separated by a space. // 'Lambda', 'School' -> 'Lambda School' // code here +var result = firsName + ' ' + lastName; +return result; + }; const getGreeting = (name) => { // Take the name string and concatenate other strings onto it so it takes the following form: // 'Sam' -> 'Hello Sam!' // code here +var result = 'Hello' + ' ' + name + '!'; +return result; + }; // If you can't remember these area formulas then head over to Google or look at the test code. @@ -119,21 +183,32 @@ const getGreeting = (name) => { const getRectangleArea = (length, width) => { // return the area of the rectangle by using length and width // code here +var result = length*width; +return result; }; const getTriangleArea = (base, height) => { // return the area of the triangle by using base and height // code here + var result = 0.5 * base * height; + return result; + }; const getCircleArea = (radius) => { // return the rounded area of the circle given the radius - // code here + // code here +var result = Math.PI*Math.pow(radius,2); +return result; + }; const getRectangularPrismVolume = (length, width, height) => { // return the volume of the 3D rectangular prism given the length, width, and height // code here +var result = length*width*height; +return result; + }; // Do not modify code below this line. diff --git a/src/project-2.js b/src/project-2.js index 5fe0047..a5a494f 100644 --- a/src/project-2.js +++ b/src/project-2.js @@ -3,6 +3,15 @@ const getBiggest = (x, y) => { // x and y are integers. Return the larger integer // if they are the same return either one + if(x>y){ + return x; + }else if(y>x){ + return y; + }else if(x===y){ + + return x; + + } }; const greeting = (language) => { @@ -11,15 +20,37 @@ const greeting = (language) => { // language: 'Spanish' -> 'Hola!' // language: 'Chinese' -> 'Ni Hao!' // if language is undefined return 'Hello!' + if(language === 'German'){ + return 'Guten Tag!'; + }else if(language === 'Spanish'){ + return 'Hola!'; + + }else if(language === 'Chinese'){ + return 'Ni Hao'; + + }else if(language === undefined){ + return 'Hello!'; + }; const isTenOrFive = (num) => { // return true if num is 10 or 5 // otherwise return false + if(num === 5 || num === 10){ + return true; + }else{ + return false; + } }; const isInRange = (num) => { // return true if num is less than 50 and greater than 20 + + if(num<50 && num>20){ + return true; + }else{ + return false; + } }; const isInteger = (num) => { @@ -29,6 +60,11 @@ const isInteger = (num) => { // -10 -> true // otherwise return false // hint: you can solve this using Math.floor + if(Number.isInteger(num)){ + return true; + }else{ + return false; + } }; const fizzBuzz = (num) => { @@ -36,6 +72,13 @@ const fizzBuzz = (num) => { // if num is divisible by 5 return 'buzz' // if num is divisible by 3 & 5 return 'fizzbuzz' // otherwise return num + if (num % 3 === 0 && num % 5=== 0){ + return fizzbuzz; + }else if (num % 3 === 0){ + return fizz; + }else if (num % 5=== 0){ + return buzz; + } }; const isPrime = (num) => { @@ -48,31 +91,44 @@ const isPrime = (num) => { const returnFirst = (arr) => { // return the first item from the array + let result = arr[0]; + return result; }; const returnLast = (arr) => { // return the last item of the array + let result = arr.length[-1]; + return result; }; const getArrayLength = (arr) => { // return the length of the array + let result = arr.length; + return result; }; const incrementByOne = (arr) => { // arr is an array of integers // increase each integer by one // return the array + var result = arr.map(x=> x+1); + return result; }; const addItemToArray = (arr, item) => { // add the item to the end of the array // return the array + var result = arr.push(item); + return result; }; const addItemToFront = (arr, item) => { // add the item to the front of the array // return the array // hint: use the array method .unshift + var result = arr.unshift(item); + return result; + }; const wordsToSentence = (words) => { @@ -80,11 +136,18 @@ const wordsToSentence = (words) => { // return a string that is all of the words concatenated together // spaces need to be between each word // example: ['Hello', 'world!'] -> 'Hello world!' + let result = 'Hello' + ' '+ 'world!'; + return result; }; const contains = (arr, item) => { // check to see if item is inside of arr // return true if it is, otherwise return false + if ( arr.indexOf(item)){ + return true; + }else { + return false; + } }; const addNumbers = (numbers) => { @@ -95,11 +158,19 @@ const addNumbers = (numbers) => { const averageTestScore = (testScores) => { // testScores is an array. Iterate over testScores and compute the average. // return the average + var total = 0; + for(var i =9; i { // numbers is an array of integers // return the largest integer + var result = Math.max(...numbers); + return result; }; // Do not modify code below this line.