diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100644 index 6b54e0b..0000000 --- a/.husky/pre-commit +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -npx eslint src diff --git a/src/boolean-conditions.js b/src/boolean-conditions.js index 5b73eb4..e63d797 100644 --- a/src/boolean-conditions.js +++ b/src/boolean-conditions.js @@ -1,10 +1,16 @@ // Initialise the didPass variable with a boolean value -let didPass +let didPass = false // 1. Create a conditional statement that changes the answer variable to the string // "Well done, you passed!" if didPass is true, or "Sorry, try again!" if didPass // is false -let answer +let answer + +if (didPass == true){ + answer = "Well done, you passed!" +} else { + answer = "Sorry, try again!" +} // 2. When you're done and the test passes, changing didPass to the opposite boolean // and run the test again to make sure it still passes diff --git a/src/multiple-conditions.js b/src/multiple-conditions.js index 46c8e76..0134034 100644 --- a/src/multiple-conditions.js +++ b/src/multiple-conditions.js @@ -7,9 +7,15 @@ const NUM = 9 // eslint-disable-line no-unused-vars // to be true if the NUM variable is more than or equal to the LOWER variable // AND is less than or equal to the UPPER variable let answerOne +if (NUM >= LOWER && NUM <= UPPER){ + answerOne = true +} +else{ + answerOne = false; +} // Task 2 -const STR = null +const STR = "Hello"; // 2. Use conditional statements to set the answerTwo variable below to true // if the STR variable is 'Hello' or 'Goodbye' @@ -17,9 +23,15 @@ const STR = null // Run the test after setting STR to 'Hello', then 'Goodbye', then any other value you like // to verify your code is correct let answerTwo +if (STR === "Hello" || STR === "Goodbye") { + answerTwo = true; +} else { + answerTwo = false; +} + // Task 3 -const AGE = 0 +const AGE = 8 // 3. Use conditional statements to set the answerThree variable below to a // string value based on what the AGE variable is set to. @@ -35,6 +47,18 @@ const AGE = 0 // 20+ | Adult let answerThree +if (AGE === 0) { + answerThree = 'Baby'; +} else if (AGE >= 1 && AGE <= 4) { + answerThree = 'Toddler'; +} else if (AGE >= 5 && AGE <= 12) { + answerThree = 'Child'; +} else if (AGE >= 13 && AGE <= 19) { + answerThree = 'Teenager'; +} else if (AGE >= 20) { + answerThree = 'Adult'; +} + // Run the test after changing the AGE value to verify you've successfully // accounted for each age range diff --git a/src/numeric-conditions.js b/src/numeric-conditions.js index 030005f..72ce255 100644 --- a/src/numeric-conditions.js +++ b/src/numeric-conditions.js @@ -9,16 +9,36 @@ const ARRAY_TWO = ['Hello', 'Conditions', NUM_ONE] // eslint-disable-line no-unu // 1. Use conditional statements to set answerOne to false if ARRAY_ONE is not empty // or true if it is empty let answerOne +if (ARRAY_ONE.length === 0) { + answerOne = true; +} else { + answerOne = false; +} // 2. Use conditional statements to set answerTwo to false if ARRAY_TWO is not empty // or true if it is empty let answerTwo +if (ARRAY_TWO.length === 0) { + answerTwo = true; +} else { + answerTwo = false; +} // 3. Use conditional statements to set answerThree to true if NUM_ONE is more than NUM_TWO let answerThree +if (NUM_ONE > NUM_TWO) { + answerThree = true; +} else { + answerThree = false; +} // 4. Use conditional statements to set answerFour to true if NUM_ONE or NUM_TWO are included in ARRAY_TWO let answerFour +if (ARRAY_TWO.includes(NUM_ONE) || ARRAY_TWO.includes(NUM_TWO)) { + answerFour = true; +} else { + answerFour = false; +} // Don't edit the code below this line module.exports = { diff --git a/src/string-conditions.js b/src/string-conditions.js index 71d3944..a340290 100644 --- a/src/string-conditions.js +++ b/src/string-conditions.js @@ -2,11 +2,21 @@ const STR_ONE = 'Hello' // eslint-disable-line no-unused-vars let answerOne +if (STR_ONE === 'Hello') { + answerOne = true; +} else { + answerOne = false; +} // 2. Use conditional statements to set answerTwo to true if STR_TWO is not 'Hello' const STR_TWO = 'Goodbye' // eslint-disable-line no-unused-vars let answerTwo +if (STR_TWO !== 'Hello') { + answerTwo = true; +} else { + answerTwo = false; +} // 3. Use conditional statements to set answerThree to true if STR_THREE is // longer than STR_FOUR @@ -14,6 +24,11 @@ const STR_THREE = 'Hello' // eslint-disable-line no-unused-vars const STR_FOUR = 'Good' // eslint-disable-line no-unused-vars let answerThree +if (STR_THREE.length > STR_FOUR.length) { + answerThree = true; +} else { + answerThree = false; +} // 4. Use conditional statements to set answerFour to true // if STR_FIVE starts and ends with the same character, regardless of case @@ -21,6 +36,11 @@ let answerThree const STR_FIVE = 'Alexandra' // eslint-disable-line no-unused-vars let answerFour +if (STR_FIVE.charAt(0).toLowerCase() === STR_FIVE.charAt(8).toLowerCase()) { + answerFour = true; +} else { + answerFour = false; +} // 5. Use conditional statements to set answerFive to true // if STR_SIX starts and ends with the same character, regardless of case @@ -28,18 +48,30 @@ let answerFour const STR_SIX = 'Joanna' // eslint-disable-line no-unused-vars let answerFive +if (STR_SIX.charAt(0).toLowerCase() === STR_SIX.charAt(5).toLowerCase()) { + answerFive = true; +} else { + answerFive = false; +} // 6. Use conditional statements to set answerSix to the middle character of STR_SEVEN // if STR_SEVEN has an odd number of characters const STR_SEVEN = 'Kayla' // eslint-disable-line no-unused-vars let answerSix +if (STR_SEVEN.length % 2 !== 0) { + answerSix = STR_SEVEN.charAt(Math.floor(STR_SEVEN.length / 2)); +} // 7. Use conditional statements to set answerSeven to the middle two characters of // STR_EIGHT if STR_EIGHT has an even number of characters const STR_EIGHT = 'Alex' // eslint-disable-line no-unused-vars let answerSeven +if (STR_EIGHT.length % 2 === 0) { + const middle = STR_EIGHT.length / 2; + answerSeven = STR_EIGHT.slice(middle - 1, middle + 1); +} // 8. Set answerEight to the appropriate season based on what MONTH is set to // @@ -57,6 +89,16 @@ const MONTH = 'January' let answerEight +if (['December', 'January', 'February'].includes(MONTH)) { + answerEight = 'Winter'; +} else if (['March', 'April', 'May'].includes(MONTH)) { + answerEight = 'Spring'; +} else if (['June', 'July', 'August'].includes(MONTH)) { + answerEight = 'Summer'; +} else if (['September', 'October', 'November'].includes(MONTH)) { + answerEight = 'Autumn'; +} + module.exports = { answerOne, answerTwo,