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
6 changes: 6 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
console.log("Hello world");

console.log("Hi, my name is Zahraa.")

// console.log(Hi, my name is Zahraa.)

console.log(50)
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`

var greeting = "Hi, how are you?"
console.log(greeting);
console.log(greeting);
console.log(greeting);
4 changes: 4 additions & 0 deletions exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Start by creating a variable `message`

var message = "This is a lovely day!";
var messageType = typeof message;

console.log(message);
console.log(messageType);
5 changes: 5 additions & 0 deletions exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Start by creating a variable `message`

var messageStart = "Hello, my name is ";
var name = "Zahraa";

var message = messageStart + name;

console.log(message);
4 changes: 4 additions & 0 deletions exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Start by creating a variable `message`

var name = "Zahraa";
var nameLength = name.length;
var message = `Hello, my name is ${name} which is ${nameLength} characters long.`
Comment thread
zahraateee marked this conversation as resolved.

console.log(message);
6 changes: 5 additions & 1 deletion exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const name = " Daniel ";
var nameLength = name.length;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Even better, you could show the length of the trimmed string?

// var message = "My name is " + name + "and my name is " + nameLength + " characters long"

console.log(message);
var message = `Hello, my name is ${name} which is ${nameLength} characters long.`

console.log(message.trim());
9 changes: 9 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`

var numberOfStudents = 60;
var numberOfMentors = 5;

var sumStudentsAndMentors = numberOfStudents + numberOfMentors;

console.log(`Number of students: ${numberOfStudents}`)
console.log(`Number of mentors: ${numberOfMentors}`)
console.log(`Total number of students and mentors: ${sumStudentsAndMentors}`)
11 changes: 11 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
var numberOfStudents = 15;
var numberOfMentors = 8;

var total = numberOfStudents + numberOfMentors;

var percentStudents = numberOfStudents / total * 100;
var percentMentors = numberOfMentors / total * 100;

var roundedPercentStudents = Math.round(percentStudents);
var roundedPercentMentors = Math.round(percentMentors);

console.log(`${roundedPercentStudents}%`);
console.log(`${roundedPercentMentors}%`);
2 changes: 1 addition & 1 deletion exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function halve(number) {
// complete the function here
return number / 2;
}

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

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

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

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

var result = divide(3, 4);

Expand Down
4 changes: 3 additions & 1 deletion exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Write your function here
function createGreeting(name) {
return `Hello, my name is ${name}`;
}

var greeting = createGreeting("Daniel");

Expand Down
6 changes: 4 additions & 2 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Declare your function first
function addition(a, b) {
return a + b;
}

// Call the function and assign to a variable `sum`
let sum = addition(13, 124);

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

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

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

function greeting(name) {
return `Hello ${name}`.toUpperCase();
}

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

function convertToUSD() {}
function convertToUSD(pounds) {
dollars = pounds * 1.4;
return "$" + dollars.toFixed(2);
}

console.log(convertToUSD(32))

/*
CURRENCY CONVERSION
Expand All @@ -15,7 +20,13 @@ 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(pounds) {
let taxedPounds = pounds / 0.99;
let brazilianReal = taxedPounds * 5.7;
return "$" + brazilianReal.toFixed(2);
}

console.log(convertToBRL(9))

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

function add() {

function add(a, b) {
return a + b;
}

function multiply() {

function multiply(c, d) {
return c * d;
}

function format() {

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

const startingValue = 2;

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
let badCode = format(multiply(add(10, startingValue), 2))

console.log(badCode)

/* BETTER PRACTICE */

let goodCode =
let added = add(10, startingValue);
let multiplied = multiply(2, added);
let formatted = format(multiplied);

let goodCode = formatted;

console.log(goodCode)

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
35 changes: 34 additions & 1 deletion extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,43 @@
Very doubtful.
*/

const veryPositiveAnswers = [
"It is certain.",
"It is decidedly so.",
"Without a doubt.",
"Yes - definitely.",
"You may rely on it."
]

const positiveAnswers = [
"As I see it, yes.",
"Most likely.",
"Outlook good.",
"Yes.",
"Signs point to yes."
]

const negative = [
"Reply hazy, try again.",
"Ask again later.",
"Better not tell you now.",
"Cannot predict now.",
"Concentrate and ask again."
]

const veryNegative = [
"Don't count on it.",
"My reply is no.",
"My sources say no.",
"Outlook not so good.",
"Very doubtful."
]

// This should log "The ball has shaken!"
// and return the answer.
function shakeBall() {
//Write your code in here
answer = "The ball has shaken!";
return answer;
}

/*
Expand Down
17 changes: 12 additions & 5 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
// 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";
console.log(addNumbers(3, 4, 5))

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

console.log(introduceMe("Zahraa ", 24))

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

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

console.log(getTotal(3, 4))

/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
13 changes: 9 additions & 4 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
// 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();
}

console.log(trimWord( "CodeYourFuture" ))

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

console.log(getStringLength("Zahraa"))

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

console.log(multiply(2, 3, 4))

/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
9 changes: 7 additions & 2 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
// Add comments to explain what this function does. You're meant to use Google!
function getRandomNumber() {
return Math.random() * 10;
}
} // This function picks a random number between 0 and 1, then multiplies it by 10.

console.log(getRandomNumber(9))

// Add comments to explain what this function does. You're meant to use Google!
function combine2Words(word1, word2) {
return word1.concat(word2);
}
} // Joins 2 or more strings together >>>>>> `word1word2`

function concatenate(firstWord, secondWord, thirdWord) {
return firstWord.concat(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.
}

console.log(concatenate("hello", "wassup", "Zahraa"))

/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
12 changes: 10 additions & 2 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
Sales tax is 20% of the price of the product.
*/

function calculateSalesTax() {}
function calculateSalesTax(price) {
let tax = price + (price * 20) / 100;
return tax;
}

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

function addTaxAndFormatCurrency() {}
function addTaxAndFormatCurrency(price) {
const tax = price * 0.2;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could call your calculateSalesTax function to get this value?

const priceWithTax = tax + price;
const totalPrice = `£` + priceWithTax.toFixed(2); // `.toFixed(2)` allows you to get number to 2 decimal places//
return totalPrice;
}

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