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.

12 changes: 6 additions & 6 deletions spec/variables/assignment.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { a, b } = require('../../src/variables/assignment.js')
const { a, b } = require("../../src/variables/assignment.js");

describe("Variable Assignment:", () => {
it("firstNumber is 20", () => {
expect(a).toEqual(20)
})
expect(a).toEqual(20);
});

it("secondNumber is 42", () => {
expect(b).toEqual(42)
})
})
expect(b).toEqual(42);
});
});
12 changes: 8 additions & 4 deletions src/conditional-flow/boolean-conditions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// This function should accept a boolean value and return the string
// "Well done, you passed!" if the value is true, or "Sorry, try again"
// if the value is false.
function getResult (didPass) {

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";
}
}

module.exports = {
a: getResult
}
a: getResult,
};
25 changes: 17 additions & 8 deletions src/conditional-flow/multiple-conditions.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
// 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

if (num >= lower && 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.

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

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 +32,18 @@ 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 (0 === age) return "Baby";
if (0 < age && age <= 4) return "Toddler";
if (4 < age && age <= 12) return "Child";
if (13 <= age && age <= 19) return "Teenager";
if (20 <= age) return "Adult";
}

module.exports = {
a: isInRange,
b: isHelloOrGoodbye,
c: getAgeDescription
}
c: getAgeDescription,
};
21 changes: 13 additions & 8 deletions src/conditional-flow/numeric-conditions.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
// TODO: Implement the functions below to make the tests pass

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

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

if (array.length === 0) return true;

return false;
}

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

function isGreaterThan(num1, num2) {
// TODO: write code in this function body to pass the tests
if (num1 > num2) return true;

return false;
}

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

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

let lowest = Math.min(...nums);

return lowest;
}

module.exports = {
a: isArrayEmpty,
b: isGreaterThan,
c: findLowest
}
c: findLowest,
};
85 changes: 70 additions & 15 deletions src/conditional-flow/string-conditions.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,56 @@
// This function should return true if the passed string is equal to "Hello"
function isHello (val1) {
function isHello(val1) {
if (val1 === "Hello") return true;
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) {

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

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

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

function hasOddNumberVowels(val1) {
// TODO: write code in this function body to pass the tests
let vowel_list = "aeiouAEIOU";
let vcount = 0;

for (let x = 0; x < val1.length; x++) {
if (vowel_list.indexOf(val1[x]) !== -1) {
vcount += 1;
}
}

if (vcount % 2 !== 0) return true;
return false;
}

// 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) {
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[Math.floor(val1.length / 2)];
}
}

// This function should return the name of the season for the provided
Expand All @@ -47,9 +62,49 @@ function getMiddleLetter (val1) {
// Summer - June to August
// Autumn - September to November
// Winter - December to February
function seasonForMonth (monthName) {

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

switch (monthName) {
Copy link
Contributor

@shahzadnaeem shahzadnaeem Mar 9, 2022

Choose a reason for hiding this comment

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

case "January":
case "February":
case "December":
return "Winter";

Have a look at switch() statement syntax in MDN

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 All @@ -58,5 +113,5 @@ module.exports = {
c: isLongerThan,
d: hasOddNumberVowels,
e: getMiddleLetter,
f: seasonForMonth
}
f: seasonForMonth,
};
14 changes: 7 additions & 7 deletions src/data-types/arrays/accessing-elements.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// do not edit this section
const cities = ['London', 'Shanghai', 'New York', 'Delhi', 'Kuala Lumpur']
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 = {
a: names,
b: fourthCity,
c: firstCity,
d: lengthOfCitiesArray
}
d: lengthOfCitiesArray,
};
32 changes: 16 additions & 16 deletions src/data-types/arrays/adding-removing-elements.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
// do not edit this section
const cities = ['London', 'Shanghai', 'New York', 'Delhi', 'Kuala Lumpur']
const names = []
const numbers = [1, 2, 3]
const colours = ['Red', 'Blue', 'Yellow']
const keys = ['q', 'w', 'e', 'r', 't', 'y']
const countries = ['Bolivia', 'Jordan', 'Greenland']
const fruits = ['Apple', 'Orange', 'Pear']
const cities = ["London", "Shanghai", "New York", "Delhi", "Kuala Lumpur"];
const names = [];
const numbers = [1, 2, 3];
const colours = ["Red", "Blue", "Yellow"];
const keys = ["q", "w", "e", "r", "t", "y"];
const countries = ["Bolivia", "Jordan", "Greenland"];
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 All @@ -39,5 +39,5 @@ module.exports = {
e: keys,
f: countries,
g: fruits,
h: pear
}
h: pear,
};
Loading