From b28c03bdf0b44b39b399f7df4d339a1a65aaa3f3 Mon Sep 17 00:00:00 2001 From: Ludwig J Lundborg Date: Sat, 21 Sep 2024 17:31:58 +0200 Subject: [PATCH] ALl finished --- src/boolean-conditions.js | 10 ++++++++-- src/multiple-conditions.js | 18 +++++++++++++++--- src/numeric-conditions.js | 9 +++++---- src/string-conditions.js | 36 ++++++++++++++++++++++++++++-------- 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/src/boolean-conditions.js b/src/boolean-conditions.js index 5b73eb4..3db60b7 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 = 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 +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..b064f48 100644 --- a/src/multiple-conditions.js +++ b/src/multiple-conditions.js @@ -6,7 +6,8 @@ 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 +let answerOne = NUM >= LOWER; + // Task 2 const STR = null @@ -16,7 +17,7 @@ const STR = null // 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 +let answerTwo = STR === 'Hello' || STR === 'Goodbye' // Task 3 const AGE = 0 @@ -33,7 +34,18 @@ const AGE = 0 // 5-12 | Child // 13-19 | Teenager // 20+ | Adult -let answerThree +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..c317883 100644 --- a/src/numeric-conditions.js +++ b/src/numeric-conditions.js @@ -8,17 +8,18 @@ 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 +let 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 +let answerTwo = ARRAY_TWO.length === 0 // 3. Use conditional statements to set answerThree to true if NUM_ONE is more than NUM_TWO -let answerThree +let 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 +let answerFour = ARRAY_TWO.includes(NUM_ONE) || ARRAY_TWO.includes(NUM_TWO) +console.log(answerFour) // Don't edit the code below this line module.exports = { diff --git a/src/string-conditions.js b/src/string-conditions.js index 71d3944..07d91bd 100644 --- a/src/string-conditions.js +++ b/src/string-conditions.js @@ -1,45 +1,53 @@ +const { STR } = require("./multiple-conditions") + // 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 +let 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 +let 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 +let answerThree = STR_THREE > STR_FOUR // 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 +let 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 +let answerFive = !STR_SIX.charAt(0).toLowerCase === STR_SIX.charAt(STR_FIVE.length - 1).toLowerCase // 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 +let answerSix; +if(STR_SEVEN.length % 2 === 1){ + answerSix = STR_SEVEN.charAt(STR_SEVEN.length / 2 - 0.5) +} // 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 +let answerSeven; +if(STR_EIGHT.length % 2 === 0){ + answerSeven = 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 +63,19 @@ let answerSeven // Run the test after changing the value of MONTH to check you've covered every month correctly const MONTH = 'January' -let answerEight +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{ + answerEight = 'Winter' +} module.exports = { answerOne,