From a8a9565695e4c3aa33269023919d66c0e5ab171d Mon Sep 17 00:00:00 2001 From: Jacob Chen Jensen Date: Thu, 15 Feb 2024 13:08:51 +0100 Subject: [PATCH] core and extension --- src/boolean-conditions.js | 5 +++++ src/multiple-conditions.js | 22 +++++++++++++++++-- src/numeric-conditions.js | 16 ++++++++++++++ src/string-conditions.js | 44 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/boolean-conditions.js b/src/boolean-conditions.js index 5b73eb4..8ac3a17 100644 --- a/src/boolean-conditions.js +++ b/src/boolean-conditions.js @@ -5,6 +5,11 @@ let didPass // "Well done, you passed!" if didPass is true, or "Sorry, try again!" if didPass // is false let answer +if (didPass) { + 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..d438669 100644 --- a/src/multiple-conditions.js +++ b/src/multiple-conditions.js @@ -8,8 +8,12 @@ const NUM = 9 // eslint-disable-line no-unused-vars // AND is less than or equal to the UPPER variable let answerOne +if (NUM >= LOWER && NUM <= UPPER) { + answerOne = true +} + // Task 2 -const STR = null +const STR = 'Greetings' // 2. Use conditional statements to set the answerTwo variable below to true // if the STR variable is 'Hello' or 'Goodbye' @@ -17,9 +21,14 @@ 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 = 1 // 3. Use conditional statements to set the answerThree variable below to a // string value based on what the AGE variable is set to. @@ -34,6 +43,15 @@ const AGE = 0 // 13-19 | Teenager // 20+ | Adult let answerThree +if (AGE === 0) { + answerThree = 'Baby' +} else if (AGE > 0 && AGE < 5) { + answerThree = 'Toddler' +} else if (AGE > 4 && AGE < 13) { + answerThree = 'Teenager' +} else if (AGE > 19) { + 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..d9357bf 100644 --- a/src/numeric-conditions.js +++ b/src/numeric-conditions.js @@ -9,16 +9,32 @@ 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 +} // 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 +} // Don't edit the code below this line module.exports = { diff --git a/src/string-conditions.js b/src/string-conditions.js index 71d3944..5f329e7 100644 --- a/src/string-conditions.js +++ b/src/string-conditions.js @@ -2,11 +2,17 @@ const STR_ONE = 'Hello' // eslint-disable-line no-unused-vars let answerOne +if (STR_ONE === 'Hello') { + answerOne = true +} // 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 +} // 3. Use conditional statements to set answerThree to true if STR_THREE is // longer than STR_FOUR @@ -14,6 +20,9 @@ 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 +} // 4. Use conditional statements to set answerFour to true // if STR_FIVE starts and ends with the same character, regardless of case @@ -21,6 +30,9 @@ let answerThree const STR_FIVE = 'Alexandra' // eslint-disable-line no-unused-vars let answerFour +if (STR_FIVE[0].toLowerCase() === STR_FIVE[STR_FIVE.length - 1].toLowerCase()) { + answerFour = true +} // 5. Use conditional statements to set answerFive to true // if STR_SIX starts and ends with the same character, regardless of case @@ -28,18 +40,33 @@ let answerFour const STR_SIX = 'Joanna' // eslint-disable-line no-unused-vars let answerFive +if (STR_SIX[0].toLowerCase() === STR_SIX[STR_SIX.length - 1].toLowerCase()) { + answerFive = true + console.log(STR_SIX[0], STR_SIX[STR_SIX.length - 1]) +} 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 === 1) { + answerSix = STR_SEVEN[parseInt(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) { + answerSeven = STR_EIGHT.slice( + STR_EIGHT.length / 2 - 1, + STR_EIGHT.length / 2 + 1 + ) +} // 8. Set answerEight to the appropriate season based on what MONTH is set to // @@ -56,6 +83,23 @@ let answerSeven const MONTH = 'January' let answerEight +if (MONTH === 'March' || MONTH === 'April' || MONTH === 'May') { + answerEight = 'Spring' +} else if (MONTH === 'June' || MONTH === 'July' || MONTH === 'August') { + answerEight = 'Summer' +} else if ( + MONTH === 'September' || + MONTH === 'October' || + MONTH === 'November' +) { + answerEight = 'Autumn' +} else if ( + MONTH === 'December' || + MONTH === 'January' || + MONTH === 'February' +) { + answerEight = 'Winter' +} module.exports = { answerOne,