From 6ab642352c4dae2ee053b3849b40442897214645 Mon Sep 17 00:00:00 2001 From: Malte Date: Mon, 23 Sep 2024 09:44:54 +0200 Subject: [PATCH 1/2] all works --- src/boolean-conditions.js | 4 ++-- src/multiple-conditions.js | 19 +++++++++++++++---- src/numeric-conditions.js | 8 ++++---- src/string-conditions.js | 34 +++++++++++++++++++++++++--------- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/src/boolean-conditions.js b/src/boolean-conditions.js index 5b73eb4..2ff256f 100644 --- a/src/boolean-conditions.js +++ b/src/boolean-conditions.js @@ -1,10 +1,10 @@ // Initialise the didPass variable with a boolean value -let didPass +const didPass = true // 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 +const answer = didPass === true ? 'Well done, you passed!' : '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..2844d0c 100644 --- a/src/multiple-conditions.js +++ b/src/multiple-conditions.js @@ -6,17 +6,17 @@ const NUM = 9 // eslint-disable-line no-unused-vars // 1. Use conditional statements to set the value of the answerOne variable // 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 +const answerOne = NUM >= LOWER && NUM <= UPPER // 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' // Set answerTwo to false if it's neither of those // Run the test after setting STR to 'Hello', then 'Goodbye', then any other value you like // to verify your code is correct -let answerTwo +const answerTwo = STR === 'Hello' || 'Goodbye' // Task 3 const AGE = 0 @@ -33,7 +33,18 @@ const AGE = 0 // 5-12 | Child // 13-19 | Teenager // 20+ | Adult -let answerThree +const answerThree = + AGE > 0 && AGE <= 1 + ? 'Baby' + : AGE > 1 && AGE <= 4 + ? 'Toddler' + : AGE > 4 && AGE <= 12 + ? 'Child' + : AGE >= 13 && AGE <= 19 + ? 'Teenager' + : AGE >= 20 + ? 'Adult' + : 'Unknown' // 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..fb8dfa0 100644 --- a/src/numeric-conditions.js +++ b/src/numeric-conditions.js @@ -8,17 +8,17 @@ 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 +const answerOne = ARRAY_ONE.length === 0 // 2. Use conditional statements to set answerTwo to false if ARRAY_TWO is not empty // or true if it is empty -let answerTwo +const answerTwo = ARRAY_TWO.length === 0 // 3. Use conditional statements to set answerThree to true if NUM_ONE is more than NUM_TWO -let answerThree +const answerThree = NUM_ONE > NUM_TWO // 4. Use conditional statements to set answerFour to true if NUM_ONE or NUM_TWO are included in ARRAY_TWO -let answerFour +const answerFour = ARRAY_TWO.includes(NUM_ONE) // Don't edit the code below this line module.exports = { diff --git a/src/string-conditions.js b/src/string-conditions.js index 71d3944..23535ca 100644 --- a/src/string-conditions.js +++ b/src/string-conditions.js @@ -1,45 +1,52 @@ // 1. Use conditional statements to set answerOne to true if STR_ONE is 'Hello' const STR_ONE = 'Hello' // eslint-disable-line no-unused-vars -let answerOne +const answerOne = STR_ONE === 'Hello' // 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 +const answerTwo = STR_TWO !== 'Hello' // 3. Use conditional statements to set answerThree to true if STR_THREE is // longer than STR_FOUR const STR_THREE = 'Hello' // eslint-disable-line no-unused-vars const STR_FOUR = 'Good' // eslint-disable-line no-unused-vars -let answerThree +const answerThree = STR_THREE.length > STR_FOUR.length // 4. Use conditional statements to set answerFour to true // if STR_FIVE starts and ends with the same character, regardless of case const STR_FIVE = 'Alexandra' // eslint-disable-line no-unused-vars -let answerFour +const answerFour = + STR_FIVE.charAt(0).toLowerCase() === + STR_FIVE.charAt(STR_FIVE.length - 1).toLowerCase() // 5. Use conditional statements to set answerFive to true // if STR_SIX starts and ends with the same character, regardless of case const STR_SIX = 'Joanna' // eslint-disable-line no-unused-vars -let answerFive +const answerFive = STR_SIX.charAt(0) === STR_SIX.charAt(STR_SIX.length - 1) // 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 +const answerSix = + STR_SEVEN.length % 2 === 1 ? STR_SEVEN.charAt(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 +// two chars need ot be merged +const answerSeven = + STR_EIGHT.length % 2 === 0 + ? STR_EIGHT.charAt(STR_EIGHT.length / 2 - 1) + + STR_EIGHT.charAt(STR_EIGHT.length / 2) + : '' // 8. Set answerEight to the appropriate season based on what MONTH is set to // @@ -55,7 +62,16 @@ let answerSeven // Run the test after changing the value of MONTH to check you've covered every month correctly const MONTH = 'January' -let answerEight +const answerEight = + MONTH === 12 || MONTH === 1 || MONTH === 2 + ? 'Winter' + : MONTH === 3 || MONTH === 4 || MONTH === 5 + ? 'Spring' + : MONTH === 6 || MONTH === 7 || MONTH === 8 + ? 'Summer' + : MONTH === 9 || MONTH === 10 || MONTH === 11 + ? 'Autumn' + : 'Unknown' module.exports = { answerOne, From 7e7a1635955218aba1f7881fc86e92db2ed6c2c5 Mon Sep 17 00:00:00 2001 From: Malte Date: Mon, 23 Sep 2024 09:49:15 +0200 Subject: [PATCH 2/2] Minor fix due to unintentional change in code --- src/multiple-conditions.js | 2 +- src/string-conditions.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/multiple-conditions.js b/src/multiple-conditions.js index 2844d0c..1b58307 100644 --- a/src/multiple-conditions.js +++ b/src/multiple-conditions.js @@ -34,7 +34,7 @@ const AGE = 0 // 13-19 | Teenager // 20+ | Adult const answerThree = - AGE > 0 && AGE <= 1 + AGE === 0 && AGE <= 1 ? 'Baby' : AGE > 1 && AGE <= 4 ? 'Toddler' diff --git a/src/string-conditions.js b/src/string-conditions.js index 23535ca..fb31809 100644 --- a/src/string-conditions.js +++ b/src/string-conditions.js @@ -63,13 +63,13 @@ const answerSeven = const MONTH = 'January' const answerEight = - MONTH === 12 || MONTH === 1 || MONTH === 2 + MONTH === 'December' || MONTH === 'January' || MONTH === 'Febuary' ? 'Winter' - : MONTH === 3 || MONTH === 4 || MONTH === 5 + : MONTH === 'Mars' || MONTH === 'April' || MONTH === 'May' ? 'Spring' - : MONTH === 6 || MONTH === 7 || MONTH === 8 + : MONTH === 'June' || MONTH === 'July' || MONTH === 'August' ? 'Summer' - : MONTH === 9 || MONTH === 10 || MONTH === 11 + : MONTH === 'September' || MONTH === 'October' || MONTH === 'November' ? 'Autumn' : 'Unknown'