diff --git a/package-lock.json b/package-lock.json index d663c98a..6751df13 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "js-fundamentals", "version": "1.0.0", "license": "ISC", "devDependencies": { diff --git a/src/conditional-flow/boolean-conditions.js b/src/conditional-flow/boolean-conditions.js index 70b623d4..d57b96a8 100644 --- a/src/conditional-flow/boolean-conditions.js +++ b/src/conditional-flow/boolean-conditions.js @@ -2,7 +2,7 @@ // "Well done, you passed!" if the value is true, or "Sorry, try again" // if the value is false. function getResult (didPass) { - +return didPass === true ? 'Well done, you passed!' : 'Sorry, try again' // TODO: write code in this function body to pass the tests } diff --git a/src/conditional-flow/multiple-conditions.js b/src/conditional-flow/multiple-conditions.js index 80420abf..d7833d69 100644 --- a/src/conditional-flow/multiple-conditions.js +++ b/src/conditional-flow/multiple-conditions.js @@ -2,7 +2,7 @@ // than or equal to lower AND less than or equal to upper. // Implement this with a single condition. function isInRange (num, lower, upper) { - +return (lower<=num&&num<=upper); // TODO: write code in this function body to pass the tests } @@ -11,7 +11,11 @@ function isInRange (num, lower, upper) { // to "Hello" or "Goodbye". Implement this with a single // if statement. function isHelloOrGoodbye (val1) { - +if (val1 === "Hello" || val1 === "Goodbye") { + return true; +} else { + return false +} // TODO: write code in this function body to pass the tests } @@ -29,7 +33,17 @@ function isHelloOrGoodbye (val1) { // 13-19 | Teenager // 20+ | Adult function getAgeDescription (age) { - +if (age === 0) { + return "Baby" + } else if (1<=age&&age<=4){ + return "Toddler" + } else if (5<=age&&age<=12){ + return "Child" + } else if (13<=age&&age<=19){ + return "Teenager" + } else if (age>=20){ + return "Adult" + } // TODO: write code in this function body to pass the tests } diff --git a/src/conditional-flow/numeric-conditions.js b/src/conditional-flow/numeric-conditions.js index 0f6656a5..fc57cd5d 100644 --- a/src/conditional-flow/numeric-conditions.js +++ b/src/conditional-flow/numeric-conditions.js @@ -2,21 +2,26 @@ // This function should return true if there are no elements in the array, false otherwise function isArrayEmpty (array) { - + return array.length === 0 ? true : false; // TODO: write code in this function body to pass the tests } // This function should return true if num1 is greater than num2, false otherwise function isGreaterThan (num1, num2) { - + return num1 > num2 == true; // TODO: write code in this function body to pass the tests } // This function should return the lowest number in the passed array function findLowest (nums) { - + let lowest = nums[0]; + for (i=1;i<=nums.length;i++){ + if (nums[i] < lowest) { + lowest = nums[i] + } + } return lowest // TODO: write code in this function body to pass the tests } diff --git a/src/conditional-flow/string-conditions.js b/src/conditional-flow/string-conditions.js index d91bfaf0..66a47507 100644 --- a/src/conditional-flow/string-conditions.js +++ b/src/conditional-flow/string-conditions.js @@ -1,13 +1,13 @@ // This function should return true if the passed string is equal to "Hello" function isHello (val1) { - + return val1 === "Hello" // TODO: write code in this function body to pass the tests } // This function should return true if the passed string is not equal to "Hello" function isNotHello (val1) { - + return !isHello(val1) // TODO: write code in this function body to pass the tests } @@ -15,16 +15,24 @@ function isNotHello (val1) { // This function should return true if the string val1 is is longer // than string val2 function isLongerThan (val1, val2) { - + return val1.length>val2.length // TODO: write code in this function body to pass the tests } // This function should return true if the string passed in the function's first // argument has an odd number of vowels - function hasOddNumberVowels (val1) { - + let vowelCount=0; + for (i=0; i { + let rangeArray = []; + for (let i=upper;i>=lower;i--){ + rangeArray.unshift(i); + } + return rangeArray; +} // define a function that takes two arguments: a string and a number. // The function should return the same string but in upper case with exclamation // marks appended to the end. The number of exclamation marks should be @@ -21,9 +27,18 @@ // error, 10 | ERROR!!!!!!!!!! // // TODO: write code below +const makeCapsAndAddExclamation = (str,num) => { + let capsString = str.toUpperCase(); + let exclamationString = ''; + let createString = num => { + for (let i=1;i<=num;i++){ + exclamationString = exclamationString+'!'; + } return exclamationString; + }; return capsString+createString(num); + } // change the exported value to be the name of the function you defined module.exports = { - a: undefined, // change undefined to be the name of the function defined to create the range of numbers (the first todo) - b: undefined // change undefined to be the name of the function defined to return the string with exclamations (the second todo) + a: createRangeArray, // change undefined to be the name of the function defined to create the range of numbers (the first todo) + b: makeCapsAndAddExclamation // change undefined to be the name of the function defined to return the string with exclamations (the second todo) } diff --git a/src/functions/creating-functions.js b/src/functions/creating-functions.js index 2d2ac5e6..3e3bcd78 100644 --- a/src/functions/creating-functions.js +++ b/src/functions/creating-functions.js @@ -7,7 +7,9 @@ // 2 | 3 // // TODO: write code below - +const addOne = num => { + return num + 1; +} // Define a function that takes any person's name and returns it with a smiley :)! // Remember to make the name capitalized! // @@ -18,9 +20,14 @@ // Aiyana | Hi, Aiyana :) // // TODO: write code below - +const smileyGreeting = str => { + let firstLetter = str => { + return str.slice(0,1).toUpperCase() + } + return `Hi, ${firstLetter(str) + str.substring(1,str.length)} :)` + } // TODO: change undefined to be the name of the functions you defined module.exports = { - a: undefined, // change undefined to be the name of the function you defined to increment a number (the first TODO) - b: undefined // change undefined to be the name of the function you defined to say hi (the second TODO) + a: addOne, // change undefined to be the name of the function you defined to increment a number (the first TODO) + b: smileyGreeting // change undefined to be the name of the function you defined to say hi (the second TODO) } diff --git a/src/loops/for-loop-and-arrays.js b/src/loops/for-loop-and-arrays.js index 682995ec..9ddf2b0e 100644 --- a/src/loops/for-loop-and-arrays.js +++ b/src/loops/for-loop-and-arrays.js @@ -7,19 +7,29 @@ let word = '' // Use a for loop to set the sum variable to the sum of all the values in nums sum = 0 - +for (let i=0;i