Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5ef801f
Variable assignment completed
Anicaaa Mar 3, 2022
fefb8f6
Variable declaration completed
Anicaaa Mar 3, 2022
83e8a99
data types numbers completed
Anicaaa Mar 3, 2022
6f19744
Data Types strings completed
Anicaaa Mar 3, 2022
8214b48
Arrays accessing elements completed
Anicaaa Mar 3, 2022
14c9e0e
Arrays adding and removing completed
Anicaaa Mar 3, 2022
dec5ab7
Object Keys done
Anicaaa Mar 6, 2022
f185441
creating objects done
Anicaaa Mar 6, 2022
b958460
objects and arrays done
Anicaaa Mar 6, 2022
f57d789
For Loop Basic done
Anicaaa Mar 7, 2022
1a0a6c7
Loops and Arrays exercise
Anicaaa Mar 7, 2022
2fb3708
calling functions done
Anicaaa Mar 8, 2022
2e21ff1
creating function complete
Anicaaa Mar 8, 2022
ec0d844
creating functions multiple args complete
Anicaaa Mar 8, 2022
1a23e21
creating functions multiple args completed (Ed example)
Anicaaa Mar 9, 2022
06f2ba0
boolean conditions completed
Anicaaa Mar 9, 2022
b761c62
String Conditions NOT completed
Anicaaa Mar 9, 2022
9a3f50a
string conditions completed
Anicaaa Mar 10, 2022
901194b
Multiple Conditions completed
Anicaaa Mar 13, 2022
9f9ac07
Boolean conditions refactored
Anicaaa Mar 13, 2022
1e95c78
Numeric Conditions refactored
Anicaaa Mar 13, 2022
32ba232
Arrays - accessing elements refactored
Anicaaa Mar 13, 2022
13d335b
Arrays adding-removing elements refactored
Anicaaa Mar 13, 2022
942848b
data tyoes numbers refactored
Anicaaa Mar 13, 2022
ca20171
data types - creating objects refactored
Anicaaa Mar 13, 2022
c73e6a8
for loop basic refactored
Anicaaa Mar 13, 2022
57ce1ee
object and arrays refactored
Anicaaa Mar 13, 2022
ba950b8
objects and arrays refactored
Anicaaa Mar 13, 2022
4a69e1e
Demo completed
Anicaaa Mar 13, 2022
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: 6 additions & 1 deletion src/conditional-flow/boolean-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
function getResult (didPass) {

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

if (didPass === true)
return 'Well done, you passed!'
else (didPass === false)
return 'Sorry, try again'
}

module.exports = {
a: getResult
}

// npx jasmine spec/conditional-flow/boolean-conditions.spec.js
26 changes: 23 additions & 3 deletions src/conditional-flow/multiple-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@
function isInRange (num, lower, upper) {

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

if (num >= lower && num <= upper) {
return true;
} else {
return false;
}
}


// 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;
} else {
return false;
}
}

// This function should return a string that describes the provided age value. The
Expand All @@ -31,10 +40,21 @@ function isHelloOrGoodbye (val1) {
function getAgeDescription (age) {

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

module.exports = {
a: isInRange,
b: isHelloOrGoodbye,
c: getAgeDescription
}
}
20 changes: 20 additions & 0 deletions src/conditional-flow/numeric-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@
function isArrayEmpty (array) {

// TODO: write code in this function body to pass the tests
if (array.length === 0) {
return true
}
else {
return false
}

}

// 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
if (num1 > num2) {
return true
}
else {
return false
}

}

Expand All @@ -19,10 +31,18 @@ function findLowest (nums) {

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

// PseudoCode:
// 1. You want to find the lowest number inside this array [10, 8, 4, 1, 8].
// 2. It's 1, so show it using Math.min
// 3. return the result. It will happen automatically when you write down the const name (lowestNum)
const lowestNum = Math.min(...nums)
return lowestNum
}

module.exports = {
a: isArrayEmpty,
b: isGreaterThan,
c: findLowest
}

// npx jasmine spec/conditional-flow/numeric-conditions.spec.js
47 changes: 42 additions & 5 deletions src/conditional-flow/string-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@
function isHello (val1) {

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

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

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

// This function should return true if the string passed in the function's first
Expand All @@ -26,16 +38,28 @@ function isLongerThan (val1, val2) {
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
// 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 === 0) {
return val1[val1.length / 2 - 1] + val1[val1.length / 2]
} else {
return val1[(val1.length + 1) / 2 - 1]
}
}

// This function should return the name of the season for the provided
Expand All @@ -50,6 +74,17 @@ function getMiddleLetter (val1) {
function seasonForMonth (monthName) {

// TODO: write code in this function body to pass the tests
if (monthName === 'March' || monthName === 'April' || monthName === 'May') {
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 ''
}
}

module.exports = {
Expand All @@ -60,3 +95,5 @@ module.exports = {
e: getMiddleLetter,
f: seasonForMonth
}

// npx jasmine spec/conditional-flow/string-conditions.spec.js
10 changes: 6 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 All @@ -22,3 +22,5 @@ module.exports = {
c: firstCity,
d: lengthOfCitiesArray
}

// npx jasmine spec/data-types/arrays/accessing-elements.spec.js
16 changes: 9 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('Pear')

// Do not edit this exported object
module.exports = {
Expand All @@ -41,3 +41,5 @@ module.exports = {
g: fruits,
h: pear
}

// npx jasmine spec/data-types/arrays/adding-removing-elements.spec.js
14 changes: 8 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 All @@ -32,3 +32,5 @@ module.exports = {
e: sum,
f: numBytes
}

// npx jasmine spec/data-types/numbers.spec.js
14 changes: 12 additions & 2 deletions src/data-types/objects/creating-objects.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
// 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 = {
person: person,
computer: computer
}

// npx jasmine spec/data-types/objects/creating-objects.spec.js
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 = '9780132350884'

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 @@ -22,10 +22,20 @@ 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 = 2

// Set this variable to the first element in of the baskets voucher codes array
const firstVoucherCode = null
const firstVoucherCode = 'AA-AA-A'

basket.items[0].price = 2

const orange = {
name: 'Oranges',
price: 0.75,
quantity: 4
};

basket.items.push (orange)

// Do not edit this exported object
module.exports = {
Expand Down
Loading