Skip to content
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
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/conditional-flow/boolean-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
// "Well done, you passed!" if the value is true, or "Sorry, try again"
// if the value is false.
function getResult (didPass) {

// TODO: write code in this function body to pass the tests

if (didPass) {
return "Well done, you passed!"
}
return "Sorry, try again"
}

// if well done phrase is not displayed then it assume you did not pass and display try again
module.exports = {
a: getResult
}
26 changes: 23 additions & 3 deletions src/conditional-flow/multiple-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
// than or equal to lower AND less than or equal to upper.
// Implement this with a single condition.
function isInRange (num, lower, upper) {

// TODO: write code in this function body to pass the tests

return (num >= lower && num <= upper)
}

// This function should return true if the passed string is equal
// to "Hello" or "Goodbye". Implement this with a single
// if statement.
function isHelloOrGoodbye (val1) {

// TODO: write code in this function body to pass the tests

if (val1 === 'Hello' || val1 === 'Goodbye') {
return true
}
return false
}

// This function should return a string that describes the provided age value. The
Expand All @@ -29,8 +32,25 @@ function isHelloOrGoodbye (val1) {
// 13-19 | Teenager
// 20+ | Adult
function getAgeDescription (age) {

// TODO: write code in this function body to pass the tests

let description = ''
if (age === 0) {
description = 'Baby'
}
else if (age < 5) {
description = 'Toddler'
}
else if (age < 13) {
description = 'Child'
}
else if (age < 20) {
description = 'Teenager'
}
else {
description = 'Adult'
}
return description
}

module.exports = {
Expand Down
12 changes: 9 additions & 3 deletions src/conditional-flow/numeric-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@

// This function should return true if there are no elements in the array, false otherwise
function isArrayEmpty (array) {

// TODO: write code in this function body to pass the tests

return (array.length === 0)
}

// This function should return true if num1 is greater than num2, false otherwise
function isGreaterThan (num1, num2) {

// TODO: write code in this function body to pass the tests

return (num1 > num2)
}

// This function should return the lowest number in the passed array
function findLowest (nums) {

// TODO: write code in this function body to pass the tests

let smallest = nums[0]
for (let i = 1; i < nums.length; i++) {
if (nums[i] < smallest) {
smallest = nums[i]
}
}
return smallest
}

module.exports = {
Expand Down
75 changes: 66 additions & 9 deletions src/conditional-flow/string-conditions.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
// This function should return true if the passed string is equal to "Hello"
function isHello (val1) {

// TODO: write code in this function body to pass the tests

// return (val1 === 'Hello')
if (val1 === "Hello") return true;
return false;
}

// This function should return true if the passed string is not equal to "Hello"
function isNotHello (val1) {

// TODO: write code in this function body to pass the tests

// return (val1 !== 'Hello')
if (val1 !== "Hello") return true;
return false;
}

// This function should return true if the string val1 is is longer
// than string val2
function isLongerThan (val1, val2) {

// TODO: write code in this function body to pass the tests

if (val1.length > val2.length) return true;
return false;
}

// This function should return true if the string passed in the function's first
// argument has an odd number of vowels

function hasOddNumberVowels (val1) {

// TODO: write code in this function body to pass the tests

const VOWELS = ['a', 'e', 'i', 'o', 'u']
let total = 0
for (let i = 0; i < val1.length; i++) {
if (VOWELS.includes(val1[i].toLowerCase())) {
total++
}
}
return Boolean(total % 2)
}

// this function should return the middle character of a string if it has an odd number
Expand All @@ -36,6 +44,16 @@ function hasOddNumberVowels (val1) {
function getMiddleLetter (val1) {
// TODO: write code in this function body to pass the tests

let mid = Math.round(val1.length / 2)
let chars = ""
if (val1.length % 2 === 0) {
chars += val1[mid - 1]
chars += val1[mid]
}
else {
chars += val1[mid - 1]
}
return chars
}

// This function should return the name of the season for the provided
Expand All @@ -48,8 +66,47 @@ function getMiddleLetter (val1) {
// Autumn - September to November
// Winter - December to February
function seasonForMonth (monthName) {

// TODO: write code in this function body to pass the tests
switch (monthName) {
case (monthName = "January"):
return "Winter";
break;
case (monthName = "February"):
return "Winter";
break;
case (monthName = "December"):
return "Winter";
break;
case (monthName = "March"):
return "Spring";
break;
case (monthName = "April"):
return "Spring";
break;
case (monthName = "May"):
return "Spring";
break;
case (monthName = "June"):
return "Summer";
break;
case (monthName = "July"):
return "Summer";
break;
case (monthName = "August"):
return "Summer";
break;
case (monthName = "September"):
return "Autumn";
break;
case (monthName = "October"):
return "Autumn";
break;
case (monthName = "November"):
return "Autumn";
break;
default:
return "";
}
}

module.exports = {
Expand Down
8 changes: 4 additions & 4 deletions src/data-types/arrays/accessing-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ const cities = ['London', 'Shanghai', 'New York', 'Delhi', 'Kuala Lumpur']
// TODO: write code to pass the tests

// Set names equal to an array containing 'Bob', 'Jane', 'Joanna' in that order
const names = null
const names = ['Bob', 'Jane', 'Joanna']

// Set fourthCity to the 4th element in the cities array
const fourthCity = ''
const fourthCity = 'Delhi'

// Set firstCity to the 1st element in the cities array
const firstCity = ''
const firstCity = 'London'

// Set lengthOfCitiesArray to the length of the cities array
const lengthOfCitiesArray = NaN
const lengthOfCitiesArray = cities.length

// Do not edit this exported object
module.exports = {
Expand Down
14 changes: 7 additions & 7 deletions src/data-types/arrays/adding-removing-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ const fruits = ['Apple', 'Orange', 'Pear']
// TODO: write code to pass the tests

// Edit this code to add 'Fred' to the names array
names.push(undefined)
names.push('Fred')

// Edit this code to add 4 to the end of the numbers array
numbers.push(NaN)
numbers.push(4)

// Edit this code to add 'Rio' to the start of the cities array
cities.unshift(undefined)
cities.unshift('Rio')

// Use an array method to remove the first item from colours
colours
colours.shift()

// Use an array method to remove the last item from keys
keys
keys.pop()

// Use an array method to remove 'Jordon' from the countries array
countries.splice(NaN, NaN)
countries.splice(1, 1)

// use an array method to remove the last item from the fruits array and store the value in the pear variable
const pear = fruits.undefined
const pear = fruits.pop()

// Do not edit this exported object
module.exports = {
Expand Down
3 changes: 3 additions & 0 deletions src/data-types/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const upperCaseHello = hello.toUpperCase()
const secondCharacterOfDog = animal.charAt(1)
const howManyVowels = vowels.length



// TODO: Update the code below using numeric operators so that the tests
// pass
const numOneMultipliedByNumTwo = numOne * numTwo
Expand All @@ -23,3 +25,4 @@ module.exports = {
c: howManyVowels,
d: numOneMultipliedByNumTwo
}

12 changes: 6 additions & 6 deletions src/data-types/numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ const numThree = 32
// TODO: Add code below using Javascript numeric operators so that the tests pass

// Set this variable to numOne added to numTwo
const numOnePlusNumTwo = NaN
const numOnePlusNumTwo = 24

// Set this variable to numThree multiplied by numTwo
const numThreeTimesNumTwo = NaN
const numThreeTimesNumTwo = 512

// Set this variable to numThree divided by numOne
const numThreeDividedByNumOne = NaN
const numThreeDividedByNumOne = 4

// Set this variable to numThree minus numOne
const numThreeMinusNumOne = NaN
const numThreeMinusNumOne = 24

// Set this variable to the sum of numOne, numTwo and numThree
const sum = NaN
const sum = 56

// Set this variable to the sum of (numOne, numTwo, numThree) divided by numOne
const numBytes = NaN
const numBytes = 7

// do not edit the exported object.
module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions src/data-types/objects/object-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const isbn13 = '978-0132350884'
// as well as modify some of the existing code

// Set this to the book name
const name = ''
const name = 'book.name'

// Set this to the isbn 10 value
const isbn10 = ''
const isbn10 = 'book.isbn.isbn10'

// Do not edit this exported object
module.exports = {
Expand Down
11 changes: 8 additions & 3 deletions src/data-types/objects/objects-and-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ const basket = {
{
name: 'Apple',
quantity: 10,
price: 1
price: 2
},
{
name: 'Lemon',
quantity: 2,
price: 0.5
},
{
name: 'Oranges',
price: 0.75,
quantity: 4
}
],
voucherCodes: [
Expand All @@ -22,10 +27,10 @@ const basket = {
// as well as modify some of the existing code

// Set this variable to the length of the baskets voucher codes array
const numberOfVoucherCodes = null
const numberOfVoucherCodes = basket.voucherCodes.length

// Set this variable to the first element in of the baskets voucher codes array
const firstVoucherCode = null
const firstVoucherCode = basket.voucherCodes[0]

// Do not edit this exported object
module.exports = {
Expand Down
8 changes: 4 additions & 4 deletions src/data-types/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ const secondName = 'Smith'
// TODO: Update the code using Javascript string operations and the variables above so that the tests pass.

// Set this variable to firstName and secondName concatenated
const fullName = null
const fullName = firstName + " " + secondName

// Set this variable to the 10th character of the alphabet variable
const tenthCharacterOfAlphabet = null
const tenthCharacterOfAlphabet = alphabet.charAt(9)

// Set this variable by calling a method on the alphabet variable to transform it to lower case
const lowerCaseAlphabet = null
const lowerCaseAlphabet = alphabet.toLowerCase()

// Set this variable by using a property on the alphabet variable to get it's length
const numberOfLettersInAlphabet = null
const numberOfLettersInAlphabet = alphabet.length

// do not edit the exported object.
module.exports = {
Expand Down
Loading