Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
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
2 changes: 2 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
console.log("Hello world");
console.log("Hello world", "hellos");
console.log(5, 5);
4 changes: 3 additions & 1 deletion exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `greeting`

let greeting = "Hello World";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Small detail: the variable's value doesn't change, so you might as well use const, just so it becomes a habit.

console.log(greeting);
console.log(greeting);
console.log(greeting);
4 changes: 3 additions & 1 deletion exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `message`

let message = "good morning";
let stringType = typeof message;
console.log(message);
console.log(messageType);
4 changes: 3 additions & 1 deletion exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `message`

let greeting = "Hello my name is";
let name = "olus";
let message = greeting + " " + name;
console.log(message);
4 changes: 3 additions & 1 deletion exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `message`

let name = "olus"
let nameLength = name.length;
let message = `my name is ${name} and my name is ${nameLength} long`;
console.log(message);
3 changes: 2 additions & 1 deletion exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const name = " Daniel ";

let pName = name.trim();
let messgae = `my name is ${pName} and my name is ${pName.length} characters long`;
console.log(message);
3 changes: 3 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents = 15
let numberOfMentors = 8
let message = ` Total number of students and mentors: ${numberOfStudents + numberOfMentors}`;
14 changes: 12 additions & 2 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
let numberOfStudents = 15;
let numberOfMentors = 8;
let sum = (numberOfStudents + numberOfMentors);

let percentage = function percent(val, total){
return (Math.round(val / total) * 100 );
}

let perOfStud = percentage(numberOfStudents, sum);
let perOfMent = percentage(numberOfMentors, sum);
console.log(`Percentage students: ${perOfStud}`);
console.log(`Percentage Mentors: ${perOfMent}`);
1 change: 1 addition & 0 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function halve(number) {
// complete the function here
return number / 2;
}

var result = halve(12);
Expand Down
1 change: 1 addition & 0 deletions exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function triple(number) {
// complete function here
return number * 3;
}

var result = triple(12);
Expand Down
3 changes: 2 additions & 1 deletion exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Complete the function so that it takes input parameters
function multiply() {
function multiply( a, b) {
// Calculate the result of the function and return it
return a * b;
}

// Assign the result of calling the function the variable `result`
Expand Down
3 changes: 3 additions & 0 deletions exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Declare your function first
function divide(a, b){
return a / b;
}

var result = divide(3, 4);

Expand Down
4 changes: 4 additions & 0 deletions exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Write your function here

function createGreeting(name){
return `Hello, my name is ${name}`
}

var greeting = createGreeting("Daniel");

console.log(greeting);
5 changes: 4 additions & 1 deletion exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Declare your function first

function addNumb( a, b ){
return a + b;
}
let sum = addNumb(13, 124);
// Call the function and assign to a variable `sum`

console.log(sum);
3 changes: 3 additions & 0 deletions exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Declare your function here
function createLongGreeting(name, number){
return `Hello, my name is ${name} and I'm ${number} years old`
}

const greeting = createLongGreeting("Daniel", 30);

Expand Down
18 changes: 18 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,21 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";


let capL = function capitalLetter(name) {
//let pName = this.name;
return name.toUpperCase();
}

function greeting(name) {
let shout = capL(name);
return ` HELLO ${shout}`
//return ` HELLO MY NAME IS ${capL(name)}`
}

console.log(greeting(mentor1));
console.log(greeting(mentor2));
console.log(greeting(mentor3));
console.log(greeting(mentor4));
console.log(greeting(mentor5));
16 changes: 14 additions & 2 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
function convertToUSD(pound) {
let dollar = pound * 1.4;
console.log(dollar);
return dollar;
}

/*
CURRENCY CONVERSION
Expand All @@ -15,8 +19,16 @@ function convertToUSD() {}
They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL.
*/

function convertToBRL() {}
function convertToBRL(pound) {
let bRail = pound * 5.7;
console.log(bRail);
let railAndFee = bRail * 0.99;
console.log(railAndFee);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hint: when you have multiple console.log in your code it can become confusing which one is printing which value. So you can use instead:
console.log("value of bRail", bRail);
or
console.log('Here>', railAndFee)

This works because console.log() takes any number of arguments and prints all of them. For instance,
console.log('Hello', 'World', 3.14)

return railAndFee.toFixed(2) * 1;
}

console.log(convertToBRL(30));
console.log(convertToUSD(32));
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.

Expand Down
15 changes: 7 additions & 8 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// There are syntax errors in this code - can you fix it to pass the tests?

function addNumbers(a b c) {
function addNumbers(a, b, c) {
return a + b + c;
}

function introduceMe(name, age)
return "Hello, my name is " + name "and I am " age + "years old";
function introduceMe(name, age) {
return "Hello, my name is " + `${name}` + " and I am " + `${age}` + " years old";
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This works, but is a bit convoluted :)

I think the idea was to add the missing + and whitespace characters


function getTotal(a, b) {
total = a ++ b;
total = a + b;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

use const. Even if the variable is declared without const or let, it's a bad idea not to use either.


return "The total is total";
return `The total is ${total}`;
}

/*
Expand All @@ -30,9 +31,7 @@ test("addNumbers adds numbers correctly", () => {
});

test("introduceMe function returns the correct string", () => {
expect(introduceMe("Sonjide", 27)).toEqual(
"Hello, my name is Sonjide and I am 27 years old"
);
expect(introduceMe("Sonjide", 27)).toEqual("Hello, my name is Sonjide and I am 27 years old");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why has this changed?

});

test("getTotal returns a string describing the total", () => {
Expand Down
11 changes: 4 additions & 7 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// The syntax for this function is valid but it has an error, find it and fix it.

function trimWord(word) {
return wordtrim();
return word.trim();
}

function getStringLength(word) {
return "word".length();
return word.length;
}

function multiply(a, b, c) {
a * b * c;
return;
return a * b * c;
}

/*
Expand All @@ -29,9 +28,7 @@ test("trimWord trims leading and trailing whitespace", () => {
});

test("trimWord doesn't remove whitespace in the middle of the string", () => {
expect(trimWord(" CodeYourFuture teaches coding ")).toEqual(
"CodeYourFuture teaches coding"
);
expect(trimWord(" CodeYourFuture teaches coding ")).toEqual("CodeYourFuture teaches coding");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why this change?

});

test("getStringLength returns the length of a word", () => {
Expand Down
20 changes: 20 additions & 0 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
// Add comments to explain what this function does. You're meant to use Google!

// the function generates a random number between 0 and <1,
//the number is never equal to 1. times the nubmeer by 10
//creates a random numbere between 0 and <10.
/*
google say : The Math.random() function returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range — which you can then scale to your desired range

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not google :) Mozilla Developer Network - the best reference


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#:~:text=The%20Math.random()%20function,scale%20to%20your%20desired%20range.
*/
function getRandomNumber() {
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!

/*
the below function joins two words together as is, so if thier is no white space the words will be read as one.

google= The concat() function concatenates the string arguments to the calling string and returns a new string. Changes to the original string or ..

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat
*/

function combine2Words(word1, word2) {
return word1.concat(word2);
}

function concatenate(firstWord, secondWord, thirdWord) {
// Write the body of this function to concatenate three words together.
// Look at the test case below to understand what this function is expected to return.
return firstWord.concat(" ", secondWord, " ", thirdWord);
}

console.log(concatenate("I", "am", 13));
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
32 changes: 29 additions & 3 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,29 @@
A business requires a program that calculates how much the price of a product is including sales tax
Sales tax is 20% of the price of the product.
*/
/*
// function does decimaal conversion and tax
function calculateSalesTax(price) {
//convert number to decimall place twin
let newPrice = price.toFixed(2);
//convert numb form string back to numb
let usePrice = newPrice * 1;
console.log(typeof usePrice);
console.log(usePrice);
let taxPrice = usePrice * 1.2;
let showPrice = taxPrice.toFixed(2);
console.log(showPrice);
return `£ ${showPrice}`;
}
calculateSalesTax(15);
*/
Comment on lines +7 to +22

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove


function calculateSalesTax() {}

function calculateSalesTax(price) {
let taxPrice = price * 1.2;
console.log(taxPrice);
return taxPrice;
}
calculateSalesTax(34);
/*
CURRENCY FORMATTING
===================
Expand All @@ -17,8 +37,14 @@ function calculateSalesTax() {}
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/

function addTaxAndFormatCurrency() {}
function addTaxAndFormatCurrency(price_tax) {
let newPrice = calculateSalesTax(price_tax);
let showPrice = newPrice.toFixed(2);
console.log(showPrice);
return `£${showPrice}`;
}

addTaxAndFormatCurrency(17.5);
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down