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.

2 changes: 1 addition & 1 deletion spec/data-types/objects/objects-and-arrays.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Objects and Arrays:', () => {
it('The price of apples should be updated to 2', () => {
expect(answers.basket.items[0].price).toEqual(2)
})

-
it('4 oranges priced at 0.75 should be added to the end of the items list', () => {
expect(answers.basket.items[2]).toEqual({
name: "Oranges",
Expand Down
10 changes: 9 additions & 1 deletion src/conditional-flow/boolean-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
// "Well done, you passed!" if the value is true, or "Sorry, try again"
// if the value is false.
function getResult (didPass) {
if (didPass) {
return "Well done, you passed!"
}
else {
return "Sorry, try again"
}

}

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

}


module.exports = {
a: getResult
Expand Down
37 changes: 33 additions & 4 deletions src/conditional-flow/multiple-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@
// than or equal to lower AND less than or equal to upper.
// Implement this with a single condition.
function isInRange (num, lower, upper) {

if (num>=lower && num<=upper) {
return true;
}
else {
return false;
}
}
// TODO: write code in this function body to pass the tests

}


// 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) {
if (val1 === "Hello" || val1 === "Goodbye") {
return true
}
return false

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

}


// This function should return a string that describes the provided age value. The
// table below shows for each range of age values what string should be returned.
Expand All @@ -28,10 +39,28 @@ function isHelloOrGoodbye (val1) {
// 5-12 | Child
// 13-19 | Teenager
// 20+ | Adult

function getAgeDescription (age) {
if (age === 0) {
return "Baby"
}
else if (age >= 1 && age <= 4) {
return "Toddler"
}
else if (age >= 5 && age <=12) {
return "Child"
}
else if (age > 12 && age < 20) {
return "Teenager"
}
else {
return "Adult"
}
}


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


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

// This function should return true if there are no elements in the array, false otherwise
function isArrayEmpty (array) {
if (array.length === 0) {
return true
}
else {
return false
}
}

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

}


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

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

}


// This function should return the lowest number in the passed array


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



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

}


module.exports = {
a: isArrayEmpty,
Expand Down
87 changes: 80 additions & 7 deletions src/conditional-flow/string-conditions.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
// This function should return true if the passed string is equal to "Hello"
function isHello (val1) {
if (val1 === "Hello"){
return true
}
if (val1 !== "Hello") {
return false
}
}

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

}

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

if (val1 !== "Hello") {
return true
}
if (val1 === "Hello") {
return false
}
}
// TODO: write code in this function body to pass the tests

}

// This function should return true if the string val1 is is longer
// than string val2

function isLongerThan (val1, val2) {
if (val1.length > val2.length) {
return true
}
else {
return false
}


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

Expand All @@ -24,20 +43,46 @@ function isLongerThan (val1, val2) {
// argument has an odd number of vowels

function hasOddNumberVowels (val1) {
const vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"];
let vowelsInString = 0;
for (let i=0; i<val1.length; i++){
if (vowels.includes(val1[i])) {
vowelsInString++
}
}
return Boolean(vowelsInString % 2);
}






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

}


// this function should return the middle character of a string if it has an odd number
// of characters. If there are an even number of characters the function should return
// the middle two letters

function getMiddleLetter (val1) {
// TODO: write code in this function body to pass the tests

if (val1.length % 2 === 1) {
let half = val1.length / 2;
let mid = Math.floor(half);
return val1[mid];
}
if (val1.length % 2 === 0) {
let middleTwo = val1.length / 2;
let middleOne = middleTwo - 1;
return val1[middleOne] + val1[middleTwo];
}
}



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

// This function should return the name of the season for the provided
// month name. For example, "January" should return "Winter". If the provided
// value is not a valid month, an empty string ("") should be returned. Use
Expand All @@ -47,10 +92,38 @@ function getMiddleLetter (val1) {
// Summer - June to August
// Autumn - September to November
// Winter - December to February

function seasonForMonth (monthName) {
switch (monthName) {
case "March":
case "April":
case "May":
season = "Spring"
break;
case "June":
case "July":
case "August":
season = "Summer"
break;
case "September":
case "October":
case "November":
season = "Autumn"
break;
case "December":
case "January":
case "February":
season = "Winter"
break;
default:
season = ""
}
return season;
}



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

module.exports = {
a: isHello,
Expand Down
9 changes: 5 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,17 @@ 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 = cities[3]

// Set firstCity to the 1st element in the cities array
const firstCity = ''
const firstCity = cities[0]

// 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
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 = numOne + numTwo

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

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

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

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

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

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