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

Michael Pope #12

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
4 changes: 2 additions & 2 deletions spec/string-conditions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ describe('answerThree', () => {
})

describe('answerFour', () => {
xit('should be true', () => {
it('should be true', () => {
expect(answerFour).toBe(true)
})
})

describe('answerFive', () => {
xit('should be false', () => {
it('should be false', () => {
expect(answerFive).toBe(false)
})
})
Expand Down
17 changes: 17 additions & 0 deletions src/boolean-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,25 @@ let didPass
// is false
let answer

if (didPass) {
answer = 'Well done, you passed!'
} 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
didPass = true

if (didPass) {
answer = 'Well done, you passed!'
} else {
answer = 'Sorry, try again!'
}

console.log(answer)

// Don't change the code below this line
module.exports = {
Expand Down
32 changes: 31 additions & 1 deletion src/multiple-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ 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
} else {
answerOne = false
}

console.log(`Should log true: ${answerOne}`)

// 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'
Expand All @@ -18,6 +26,14 @@ const STR = null
// to verify your code is correct
let answerTwo

if (STR === 'Hello' || STR === 'Goodbye') {
answerTwo = true
} else {
answerTwo = false
}

console.log(answerTwo)

// Task 3
const AGE = 0

Expand All @@ -35,6 +51,20 @@ 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'
}

console.log(answerThree)

// Run the test after changing the AGE value to verify you've successfully
// accounted for each age range

Expand Down
38 changes: 38 additions & 0 deletions src/numeric-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,54 @@ 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
} else {
answerOne = true
}

console.log(`True when empty, false when not empty: ${answerOne}`)
console.log(ARRAY_ONE)
console.log('--------')

// 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 = false
} else {
answerTwo = true
}

console.log(`True when empty, false when not empty: ${answerTwo}`)
console.log(ARRAY_TWO)
console.log('--------')

// 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
}

console.log(`Should log true: ${answerThree}`)
console.log('--------')

// 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 || NUM_TWO)) {
answerFour = true
} else {
answerFour = false
}

console.log(`Should log true: ${answerFour}`)
console.log('--------')

// Don't edit the code below this line
module.exports = {
answerOne,
Expand Down
96 changes: 96 additions & 0 deletions src/string-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,122 @@ const STR_ONE = 'Hello' // eslint-disable-line no-unused-vars

let answerOne

if (STR_ONE === 'Hello') {
answerOne = true
} else {
answerOne = false
}

console.log(`Should log true: ${answerOne}`)
console.log('--------')

// 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
}

console.log(`Should log true: ${answerTwo}`)
console.log('--------')

// 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
} else {
answerThree = false
}

console.log(`Should log true: ${answerThree}`)
console.log('--------')

// Use a combination of a loop and conditional statements to set answerFour
// to false if STR_FIVE has an odd number of vowels, or true if it has an
// even number
const STR_FIVE = 'Alex' // eslint-disable-line no-unused-vars

let answerFour
const listOfVowles = ['a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U']
let numberOfVowles = 0

for (let letter = 0; STR_FIVE.length > letter; letter++) {
if (listOfVowles.includes(STR_FIVE[letter])) {
numberOfVowles += 1
}
}

console.log(`Should be 2: ${numberOfVowles}`)

if (numberOfVowles % 2 == 0) {
answerFour = true
} else {
answerFour = false
}

console.log(`Should log true: ${answerFour}`)
console.log('--------')

// Use a combination of a loop and conditional statements to set answerFive
// to false if STR_SIX has an odd number of vowels, or true if it has an
// even number
const STR_SIX = 'Joanna' // eslint-disable-line no-unused-vars

let answerFive
numberOfVowles = 0

for (let letter = 0; STR_SIX.length > letter; letter++) {
if (listOfVowles.includes(STR_SIX[letter])) {
numberOfVowles += 1
}
}

console.log(`Should be 3: ${numberOfVowles}`)

if (numberOfVowles % 2 == 0) {
answerFive = true
} else {
answerFive = false
}

console.log(`Should log false: ${answerFive}`)
console.log('--------')

// 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[Math.floor(STR_SEVEN.length / 2)]
}

console.log(`Should log the letter y: ${answerSix}`)
console.log(`--------`)

// 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[STR_EIGHT.length / 2 - 1]
answerSeven += STR_EIGHT[STR_EIGHT.length / 2]
}

console.log(`Should log le: ${answerSeven}`)

// Set answerEight to the appropriate season based on what MONTH is set to
//
// For example, if MONTH is 'January', answerEight should be 'Winter'
Expand All @@ -56,6 +134,24 @@ let answerSeven
const MONTH = 'January'

let answerEight
const Spring = ['March', 'April', 'May']
const Summer = ['June', 'July', 'August']
const Autumn = ['September', 'October', 'November']
const Winter = ['December', 'January', 'February']

if (Spring.includes(MONTH)) {
answerEight = 'Spring'
} else if (Summer.includes(MONTH)) {
answerEight = 'Summer'
} else if (Autumn.includes(MONTH)) {
answerEight = 'Autumn'
} else if (Winter.includes(MONTH)) {
answerEight = 'Winter'
} else {
answerEight = 'Not a Month'
}

console.log(answerEight)

module.exports = {
answerOne,
Expand Down