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 src/conditional-flow/boolean-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// "Well done, you passed!" if the value is true, or "Sorry, try again"
// if the value is false.
function getResult (didPass) {

return didPass === true ? 'Well done, you passed!' : 'Sorry, try again'
// TODO: write code in this function body to pass the tests

}
Expand Down
20 changes: 17 additions & 3 deletions src/conditional-flow/multiple-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// than or equal to lower AND less than or equal to upper.
// Implement this with a single condition.
function isInRange (num, lower, upper) {

return (lower<=num&&num<=upper);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note - the brackets aren't really needed here, but if you find it easier to read like this then that's no problem :)

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

}
Expand All @@ -11,7 +11,11 @@ function isInRange (num, lower, upper) {
// to "Hello" or "Goodbye". Implement this with a single
// if statement.
function isHelloOrGoodbye (val1) {

if (val1 === "Hello" || val1 === "Goodbye") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified to

return val1 === 'Hello' || val1 === 'Goodbye'

return true;
} else {
return false
}
// TODO: write code in this function body to pass the tests

}
Expand All @@ -29,7 +33,17 @@ function isHelloOrGoodbye (val1) {
// 13-19 | Teenager
// 20+ | Adult
function getAgeDescription (age) {

if (age === 0) {
return "Baby"
} else if (1<=age&&age<=4){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might just be a personal thing for me, but I find it harder to read conditions laid out like 1<=age. I think it's easier to read when you set them out such as age >= 1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, initially I tried 1<=age<=4 but this always seems to evaluate to true?

return "Toddler"
} else if (5<=age&&age<=12){
return "Child"
} else if (13<=age&&age<=19){
return "Teenager"
} else if (age>=20){
return "Adult"
}
// TODO: write code in this function body to pass the tests
}

Expand Down
11 changes: 8 additions & 3 deletions src/conditional-flow/numeric-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

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

return array.length === 0 ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the ternary operator here. You could just use

return array.length === 0

// 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) {

return num1 > num2 == true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the == true here. num > num2 will create a boolean value. The computer will calculate this like so:

return num1 > num2 == true
return true == true
// or (depending on the values of num1/num2)
return false == true

So you could simplify it to:

return num1 > num2

// 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 lowest = nums[0];
for (i=1;i<=nums.length;i++){
if (nums[i] < lowest) {
lowest = nums[i]
}
} return lowest
// TODO: write code in this function body to pass the tests

}
Expand Down
33 changes: 26 additions & 7 deletions src/conditional-flow/string-conditions.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
// This function should return true if the passed string is equal to "Hello"
function isHello (val1) {

return val1 === "Hello"
// 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) {

return !isHello(val1)
// 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) {

return val1.length>val2.length
// TODO: write code in this function body to pass the tests

}

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

function hasOddNumberVowels (val1) {

let vowelCount=0;
for (i=0; i<val1.length; i++) {
if (val1.charAt(i).toLowerCase() === 'a'||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well! Alternative way of doing this could be to have an array containing the vowels, and check if the current letter is inside that array. The advantage of this is that it's a little more readable. For example:

const vowels = ['a', 'e', 'i', 'o', 'u']
for(let i = 0; i < val1.length; i++) {
  if(vowels.includes(val1.charAt(i)) {
    vowelCount++
  }
}

val1.charAt(i).toLowerCase() === 'e'||
val1.charAt(i).toLowerCase() === 'o'||
val1.charAt(i).toLowerCase() === 'i'||
val1.charAt(i).toLowerCase() === 'u'){
vowelCount++
}}
return vowelCount%2 === 1;
// TODO: write code in this function body to pass the tests

}
Expand All @@ -34,8 +42,11 @@ function hasOddNumberVowels (val1) {
// the middle two letters

function getMiddleLetter (val1) {
let sliceValue = val1.length/2;
// TODO: write code in this function body to pass the tests

return (val1.length%2===1) ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great use of the ternary operator!

val1.slice(sliceValue,sliceValue+1) :
val1.slice(sliceValue-1,sliceValue+1)
}

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

if (monthName==="March"||monthName==="April"||monthName==="May"){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well! As I mentioned above, it might be a little bit more readable if you used arrays containing the seasons and to check them like that. Both are good implementations though!

return "Spring"
} else if (monthName==="June"||monthName==="July"||monthName==="August"){
return "Summer"
} else if (monthName==="September"||monthName==="October"||monthName==="November"){
return "Autumn"
} else if (monthName==="December"||monthName==="January"||monthName==="February"){
return "Winter"
} else return ""
// TODO: write code in this function body to pass the tests
}

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 = 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 = numOnePlusNumTwo + numThree

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

// do not edit the exported object.
module.exports = {
Expand Down
13 changes: 11 additions & 2 deletions src/data-types/objects/creating-objects.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
// TODO: write code in this section to pass the tests. You will need to add new code
// as well as modify some of the existing code
const person = null
const computer = null
const person = {
name: 'Jane',
age: 32,
}
const computer = {
form: 'laptop',
specs: {
memory: '16GB',
storage: '1TB'
}
}

// Do not edit this exported object
module.exports = {
Expand Down
14 changes: 12 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,20 @@ 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

book.category = 'Programming'

book.pages = 464

book.isbn.isbn13 = '978-0132350884'

delete book.dimensions

delete book.isbn.asin

// Do not edit this exported object
module.exports = {
Expand Down
14 changes: 12 additions & 2 deletions src/data-types/objects/objects-and-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,21 @@ const basket = {
// TODO: write code in this section to pass the tests. You will need to add new code
// 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]

basket.items[0].price = 2

basket.items.push({
name: 'Oranges',
quantity: 4,
price: 0.75
})

// 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}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of the JS string interpolation!


// 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
4 changes: 2 additions & 2 deletions src/demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const numTwo = 2
let numThree = 0

// TODO: Update numThree so the tests pass
numThree = 0
numThree = 5

// TODO: Update the code below so that the tests pass

const numOnePlusNumTwo = 0 // Set this variable to numOne plus numTwo
const numOnePlusNumTwo = numOne+numTwo // Set this variable to numOne plus numTwo

// do not edit this section
module.exports = {
Expand Down
6 changes: 3 additions & 3 deletions src/functions/calling-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ function sayHelloManyTimes (name, times) {
// TODO: Add and update code here to make the tests pass

// Set this variable to 'Hello' by calling the sayHello function
const hello = ''
const hello = sayHello()

// Set this variable variable to 'Hello Jane' calling the sayHelloTo function
const helloToJane = ''
const helloToJane = sayHelloTo('Jane')

// Set this variable to 'Hello Bob! Hello Bob! Hello Bob!' calling the sayHelloManyTimes function
const helloToBob3Times = ''
const helloToBob3Times = sayHelloManyTimes('Bob', 3)

// do not edit below this line
module.exports = {
Expand Down
21 changes: 18 additions & 3 deletions src/functions/creating-functions-multiple-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
// -1, 1 | [-1, 0, 1]
//
// TODO: write code below

const createRangeArray = (lower,upper) => {
let rangeArray = [];
for (let i=upper;i>=lower;i--){
rangeArray.unshift(i);
}
return rangeArray;
}
// define a function that takes two arguments: a string and a number.
// The function should return the same string but in upper case with exclamation
// marks appended to the end. The number of exclamation marks should be
Expand All @@ -21,9 +27,18 @@
// error, 10 | ERROR!!!!!!!!!!
//
// TODO: write code below
const makeCapsAndAddExclamation = (str,num) => {
let capsString = str.toUpperCase();
let exclamationString = '';
let createString = num => {
for (let i=1;i<=num;i++){
exclamationString = exclamationString+'!';
} return exclamationString;
}; return capsString+createString(num);
}

// change the exported value to be the name of the function you defined
module.exports = {
a: undefined, // change undefined to be the name of the function defined to create the range of numbers (the first todo)
b: undefined // change undefined to be the name of the function defined to return the string with exclamations (the second todo)
a: createRangeArray, // change undefined to be the name of the function defined to create the range of numbers (the first todo)
b: makeCapsAndAddExclamation // change undefined to be the name of the function defined to return the string with exclamations (the second todo)
}
Loading