Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nosizo Dube #186

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/boolean-conditions.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
// 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
if (didPass === true) {
answer = 'Well done, you passed!'
console.log(answer)
} else {
answer = 'Sorry, try again!'
console.log(answer)
}

// 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
Expand Down
1 change: 0 additions & 1 deletion src/extensions/example.js
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

27 changes: 25 additions & 2 deletions src/multiple-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ 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
console.log('answerOne is', answerOne)
}
// Task 2
const STR = null

Expand All @@ -17,7 +20,13 @@ 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
console.log('answerTwo is', answerTwo)
} else if (STR !== 'Hello' || STR !== 'Goodbye') {
answerTwo = false
console.log('answerTwo is', answerTwo)
}
// Task 3
const AGE = 0

Expand All @@ -34,6 +43,20 @@ const AGE = 0
// 13-19 | Teenager
// 20+ | Adult
let answerThree
if (AGE === [1, 2, 3, 4]) {
answerThree = 'Toddler'
console.log('answerThree is', answerThree)
} else if (AGE === [5, 6, 7, 8, 9, 10, 12]) {
answerThree = 'Child'
console.log('answerThree is', answerThree)
} else if (AGE === [13, 14, 15, 16, 17, 18, 19]) {
answerThree = 'Teenager'
console.log('answerThree is', answerThree)
} else if (AGE >= 20) {
answerThree = 'Adult'
console.log('answerThree is', answerThree)
} else answerThree = 'Baby'
console.log('answerThree is', answerThree)

// Run the test after changing the AGE value to verify you've successfully
// accounted for each age range
Expand Down
23 changes: 22 additions & 1 deletion src/numeric-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,36 @@ const ARRAY_TWO = ['Hello', 'Conditions', NUM_ONE] // eslint-disable-line no-unu
// or true if it is empty
let answerOne

if (ARRAY_ONE.length !== 0) {
answerOne = false
console.log('answerOne', answerOne)
} else {
answerOne = true
console.log('answerOne ', answerOne)
}
// 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 !== undefined) {
answerTwo = false
console.log('answerTwo', answerTwo)
} else {
answerTwo = true
console.log('answerTwo', answerTwo)
}
// 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
console.log('answerThree', answerThree)
}

// 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
console.log('answerFour', answerFour)
}

// Don't edit the code below this line
module.exports = {
Expand Down
46 changes: 45 additions & 1 deletion src/string-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,77 @@
const STR_ONE = 'Hello' // eslint-disable-line no-unused-vars

let answerOne
if (STR_ONE === 'Hello') {
answerOne = true
console.log('answerOne', answerOne)
}

// 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
console.log('answerTwo', answerTwo)
}
// 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
if (STR_THREE.length > STR_FOUR.length) {
answerThree = true
console.log('answerThree', answerThree)
}

// 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
if (STR_FIVE.charAt(0) === STR_FIVE.charAt(8).toLocaleUpperCase()) {
answerFour = true
console.log('answerFour is', answerFour)
} else {
answerFour = false
console.log(answerFour)
}

// 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
if (STR_SIX.charAt(0) === STR_SIX.charAt(5)) {
answerFive = true
console.log('answerFIVE is', answerFive)
} else {
answerFive = false
console.log('answerFIVE is', answerFive)
}

// 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.slice(2, 3)
console.log('answerSix', answerSix)
}

// 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(1, 3)
console.log('answerSeven', answerSeven)
}

// 8. Set answerEight to the appropriate season based on what MONTH is set to
//
Expand All @@ -56,6 +89,17 @@ let answerSeven
const MONTH = 'January'

let answerEight
if (MONTH === ('September' || 'October' || 'November')) {
answerEight = 'Autumn'
console.log('answerEight is', answerEight)
} else if (MONTH === ('March' || 'April' || 'May')) {
answerEight = 'Spring'
console.log('answerEight is', answerEight)
} else if (MONTH === ('June' || 'July' || 'August')) {
answerEight = 'Summer'
console.log('answerEight is', answerEight)
} else answerEight = 'Winter'
console.log('answerEight is', answerEight)

module.exports = {
answerOne,
Expand Down
Loading