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.

48 changes: 24 additions & 24 deletions spec/data-types/objects/object-keys.spec.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
const answers = require('../../../src/data-types/objects/object-keys.js')
const answers = require("../../../src/data-types/objects/object-keys.js");

describe('Objects Keys:', () => {
it('name should be equal to the book name', () => {
expect(answers.name).toEqual('Clean Code')
})
describe("Objects Keys:", () => {
it("name should be equal to the book name", () => {
expect(answers.name).toEqual("Clean Code");
});

it('ISBN 10 should be equal to the book\'s ISBN 10 number', () => {
expect(answers.isbn10).toEqual('9780132350884')
})
it("ISBN 10 should be equal to the book's ISBN 10 number", () => {
expect(answers.isbn10).toEqual("9780132350884");
});

it('Book category should be Programming', () => {
expect(answers.book.category).toEqual('Programming')
})
it("Book category should be Programming", () => {
expect(answers.book.category).toEqual("Programming");
});

it('Book pages should be 464', () => {
expect(answers.book.pages).toEqual(464)
})
it("Book pages should be 464", () => {
expect(answers.book.pages).toEqual(464);
});

it('Book ISBN 13 should be 978-0132350884', () => {
expect(answers.book.isbn.isbn13).toEqual('978-0132350884')
})
it("Book ISBN 13 should be 978-0132350884", () => {
expect(answers.book.isbn.isbn13).toEqual("978-0132350884");
});

it('Book should not contain the dimensions key - it should be deleted', () => {
expect(answers.book.dimensions).not.toBeDefined()
})
it("Book should not contain the dimensions key - it should be deleted", () => {
expect(answers.book.dimensions).not.toBeDefined();
});

it('Book should not contain the asin key - it should be deleted', () => {
expect(answers.book.isbn.asin).not.toBeDefined()
})
})
it("Book should not contain the asin key - it should be deleted", () => {
expect(answers.book.isbn.asin).not.toBeDefined();
});
});
3 changes: 3 additions & 0 deletions spec/variables/assignment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ describe("Variable Assignment:", () => {
expect(b).toEqual(42)
})
})

//jasmine is for unit testing
// it() is the spec
9 changes: 8 additions & 1 deletion src/conditional-flow/boolean-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
function getResult (didPass) {

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

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

}
return (didPass ? "Well done, you passed!" : "Sorry, try again");

}
module.exports = {
a: getResult
}
32 changes: 23 additions & 9 deletions src/conditional-flow/multiple-conditions.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// This function should return true if num is greater
// than or equal to lower AND less than or equal to upper.
// Implement this with a single condition.
function isInRange (num, lower, upper) {

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

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 @@ -28,13 +31,24 @@ function isHelloOrGoodbye (val1) {
// 5-12 | Child
// 13-19 | Teenager
// 20+ | Adult
function getAgeDescription (age) {

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

if (age === 0) {
return "Baby";
} else if (age <= 4) {
return "Toddler";
} else if (age <= 12) {
return "Child";
} else if (age <= 19) {
return "Teenager";
} else {
return "Adult";
}
}

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

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

return (array.length === 0 ? true : 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

return (num1 > num2 ? true : false);
}

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

numLowest = Math.min(...nums)
return numLowest
}

module.exports = {
Expand Down
57 changes: 57 additions & 0 deletions src/conditional-flow/string-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ function isHello (val1) {

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

return ( val1 === "Hello" ? true : 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" ? true : false)

}

// This function should return true if the string val1 is is longer
Expand All @@ -18,6 +22,8 @@ function isLongerThan (val1, val2) {

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

return ( val1.length > val2.length ? true : false)

}

// This function should return true if the string passed in the function's first
Expand All @@ -27,15 +33,36 @@ function hasOddNumberVowels (val1) {

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

const count = val1.match(/[aeiou]/gi).length;

return (count % 2 !== 0 ? true : false);

}
// regEx - regular expression way to search through strings

// 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
// let numMiddle = 0
// let numsMiddle = 0

if (val1.length % 2 === 0 ){

numMiddle = (val1.length / 2) - 1;
numMiddle2 = numMiddle + 1;

return `${val1.charAt(numMiddle)}${val1.charAt(numMiddle2)}`;


} else {

numMiddle = val1.length / 2 ;

return `${val1.charAt(numMiddle)}`;
}
}

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

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

switch (monthName) {
case 'March':
case 'April':
case 'May':
szn = "Spring";
break;

case 'June':
case 'July':
case 'August':
szn = "Summer";
break;

case 'September':
case 'October':
case 'November':
szn = "Autumn";
break;

case 'December':
case 'January':
case 'February':
szn = "Winter";
break;

default:
szn = "";
}
return szn
}

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 = 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
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
Loading