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/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ Inside of `exercise.js` there's a line of code that will print "Hello world!".
- Try to `console.log()` something different. For example, 'Hello World. I just started learning JavaScript!'.
- Try to console.log() several things at once.
- What happens when you get rid of the quote marks?
It shows this error : SyntaxError: missing ) after argument list
- What happens when you console.log() just a number without quotes?
When I changed it to : console.log(1234); , it works normally and runs withnout errors.
2 changes: 1 addition & 1 deletion exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log("Hello world");
console.log(1234);
3 changes: 3 additions & 0 deletions exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `greeting`

let greeting = "Hello World";
console.log(greeting);
console.log(greeting);
console.log(greeting);
3 changes: 3 additions & 0 deletions exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `message`

let message = "This is a string";
let messageType = typeof message;
console.log(message);
console.log(messageType);
3 changes: 3 additions & 0 deletions exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `message`

let greetingStart = "Hello, My name is ";
let myName = "Mohammed";
let message = greetingStart + myName;
console.log(message);
9 changes: 8 additions & 1 deletion exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// Start by creating a variable `message`

let myName = "Mohammed";
let myNameLength = myName.length;
let message =
"My name is " +
myName +
" and my name is " +
myNameLength +
" characters long";
console.log(message);
5 changes: 4 additions & 1 deletion exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const name = " Daniel ";

var nameTrimmed = name.trim();
var nameLength = nameTrimmed.length;
message =
"My Name is " + nameTrimmed + " and my name is " + nameLength + " long";
console.log(message);
12 changes: 12 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`

let numberOfStudents = 36;
let numberOfMentors = 5;
let total = numberOfMentors + numberOfStudents;

let message1 = "Number of students: " + numberOfStudents;
let message2 = "Number of mentors: " + numberOfMentors;
let message3 = "Total number of students and mentors: " + total;

console.log(message1);
console.log(message2);
console.log(message3);
10 changes: 10 additions & 0 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;
const total = numberOfMentors + numberOfStudents;

let studentPct = numberOfStudents / total;
studentPct = Math.round(studentPct * 100) + "%";

let mentorsPct = numberOfMentors / total;
mentorsPct = Math.round(mentorsPct * 100) + "%";

console.log("Percentage students: " + studentPct);
console.log("Percentage mentors: " + mentorsPct);
3 changes: 2 additions & 1 deletion 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
let temp = number / 2;
return temp;
}

var result = halve(12);
Expand Down
3 changes: 2 additions & 1 deletion 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
let temp = number * 3;
return temp;
}

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,5 +1,8 @@
// Declare your function first

function divide(a, b) {
return a / b;
}
var result = divide(3, 4);

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

var greeting = createGreeting("Daniel");
function createGreeting(name) {
return "Hello, my name is " + name;
}
var greeting = createGreeting("Mohammed");

console.log(greeting);
5 changes: 5 additions & 0 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@

// Call the function and assign to a variable `sum`

function addNumbers(number1, number2) {
return number1 + number2;
}

sum = addNumbers(13, 124);
console.log(sum);
8 changes: 7 additions & 1 deletion exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Declare your function here

const greeting = createLongGreeting("Daniel", 30);
function createLongGreeting(name, age) {
var greeting = "Hello, my name is ";
greeting = greeting + name;
greeting = greeting + " and I'm " + age + " years old";
return greeting;
}
const greeting = createLongGreeting("Mohammed", 38);

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

function upperCase(name) {
return name.toUpperCase();
}

function greeting(name) {
var nameUpperCase = upperCase(name);
return "HELLO " + nameUpperCase;
}

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

function convertToUSD() {}
function convertToUSD(amount) {
return amount * 1.4;
}

/*
CURRENCY CONVERSION
Expand All @@ -15,7 +17,11 @@ 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(amount) {
var result = amount * 0.99 * 5.7;
result = result.toFixed(2);
return Number(result);
}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
22 changes: 12 additions & 10 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,29 @@
the final result to the variable goodCode
*/

function add() {

function add(number1, number2) {
return number1 + number2;
}

function multiply() {

function multiply(number1, number2) {
return number1 * number2;
}

function format() {

function format(amount) {
return "£" + amount;
}

const startingValue = 2;

// Why can this code be seen as bad practice? Comment your answer.
let badCode =

/* BETTER PRACTICE */

let goodCode =
//I think it's bad because it's not readable and not maintanable, and not easy to debug.
let badCode = format(multiply(add(startingValue, 10), 2));

/* BETTER PRACTICE */
let result = add(startingValue, 10);
result = multiply(result, 2);
let goodCode = format(result);
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.

Expand Down
9 changes: 8 additions & 1 deletion extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@
// This should log "The ball has shaken!"
// and return the answer.
function shakeBall() {
return "It is certain.";
console.log("The ball has shaken!");

//Write your code in here
}

let answer = shakeBall();
/*
This function should say whether the answer it is given is
- very positive
Expand All @@ -59,6 +63,7 @@ function shakeBall() {
This function should expect to be called with any value which was returned by the shakeBall function.
*/
function checkAnswer(answer) {
return "very positive";
//Write your code in here
}

Expand Down Expand Up @@ -101,7 +106,9 @@ test("magic 8 ball returns different values each time", () => {
);
}

let seenPositivities = new Set(Array.from(seenAnswers.values()).map(checkAnswer));
let seenPositivities = new Set(
Array.from(seenAnswers.values()).map(checkAnswer)
);
if (seenPositivities.size < 2) {
throw Error(
"Expected to random answers with different positivities each time shakeBall was called, but always got the same one"
Expand Down
13 changes: 7 additions & 6 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) {
var message = `Hello, my name is ${name} and I am ${age} years old`;
return message;
}

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

return "The total is total";
var total = a + b;
return `The total is ${total}`;
}

/*
Expand Down
7 changes: 3 additions & 4 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 Down
3 changes: 3 additions & 0 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// Add comments to explain what this function does. You're meant to use Google!
function getRandomNumber() {
// this function return a random floating-point number in the range 0 to less than 1
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!
function combine2Words(word1, word2) {
//this concatenate the word in the parameter in this case word2 , with the word1.
return word1.concat(word2);
}

function concatenate(firstWord, secondWord, thirdWord) {
return firstWord.concat(" " + secondWord + " ").concat(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.
}
Expand Down
10 changes: 8 additions & 2 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
Sales tax is 20% of the price of the product.
*/

function calculateSalesTax() {}
function calculateSalesTax(sales) {
return sales + sales * 0.2;
}

/*
CURRENCY FORMATTING
Expand All @@ -17,7 +19,11 @@ function calculateSalesTax() {}
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/

function addTaxAndFormatCurrency() {}
function addTaxAndFormatCurrency(sales) {
var salesIncludeTax = calculateSalesTax(sales);
var result = "£" + salesIncludeTax.toFixed(2);
return result;
}

/*
===================================================
Expand Down