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
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/exercises/E-strings-concatenation/exercise.js"
}
]
}
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");
4 changes: 4 additions & 0 deletions exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Start by creating a variable `greeting`

const 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);
6 changes: 6 additions & 0 deletions exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Start by creating a variable `message`

let greeting="Hello, my name is";

let name="Mohamed";

let message=`${greeting} ${name}`
Comment thread
Mohamed-Abdalla-1 marked this conversation as resolved.

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

console.log(message);
let name="Mohamed";
let nameLength = name.length;

console.log(nameLength);
7 changes: 7 additions & 0 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
const name = " Daniel ";


let greeting = "Hello, my name is";


let message = `${greeting} ${name.trim()} and my name is ${name.trim().length} characters long`;


console.log(message);
11 changes: 11 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents = 73;
let numberOfMentors = 17;
let totalNumber = numberOfMentors + numberOfStudents;

console.log(`Number of students: ${numberOfStudents}`)
console.log(`Number of mentors: ${numberOfMentors}`);
console.log(`Total number of students and mentors: ${totalNumber}`);




9 changes: 9 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
var numberOfStudents = 15;
var numberOfMentors = 8;

let totalNumber = numberOfMentors + numberOfStudents;

let percentageStudents = Math.round(numberOfStudents / totalNumber * 100);
let percentageMentors = Math.round(numberOfMentors / totalNumber * 100);

console.log(`Percentage students: ${percentageStudents}%`);

console.log(`Percentage mentors: ${percentageMentors}%`)
4 changes: 3 additions & 1 deletion exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
function halve(number) {
// complete the function here
let result =number/2;
return result;
}

var result = halve(12);
var result = halve(13);

console.log(result);
4 changes: 3 additions & 1 deletion exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
function triple(number) {
// complete function here
let result = number*3;
return result;
}

var result = triple(12);
var result = triple(10);

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

// Assign the result of calling the function the variable `result`
Expand Down
5 changes: 4 additions & 1 deletion 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) {
let result=a/b;
return result;
}
var result = divide(3, 4);

console.log(result);
3 changes: 3 additions & 0 deletions exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Write your function here
function createGreeting (name) {
return `Hello ${name}`;
}

var greeting = createGreeting("Daniel");

Expand Down
5 changes: 5 additions & 0 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Declare your function first

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

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

console.log(sum);
4 changes: 4 additions & 0 deletions exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Declare your function here

function createLongGreeting (name,age) {
return `Hello, my name is ${name} and I'm ${age} years old`;
}

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

console.log(greeting);
16 changes: 16 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
function upperCaseName(name) {
return name.toUpperCase();
}

function greeting(name) {
return `HELLO ${upperCaseName(name)}`;
}



var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

console.log (greeting(mentor1));
console.log(greeting(mentor2));
console.log(greeting(mentor3));
console.log(greeting(mentor4));
console.log(greeting(mentor5));
8 changes: 6 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(price) {
return Math.round(price * 1.4*100)/100;
Comment thread
Mohamed-Abdalla-1 marked this conversation as resolved.
}

/*
CURRENCY CONVERSION
Expand All @@ -15,7 +17,9 @@ 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(price) {
return Math.round(price*0.99*5.7*100)/100;
}

/* ======= 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: 14 additions & 8 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,32 @@
the final result to the variable goodCode
*/

function add() {

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

function multiply() {

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

function format() {

function format(a) {
return `£`+a;
}


const startingValue = 2;

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
// It's hard to read it.
let badCode = format(multiply(add(startingValue,10),2));


/* BETTER PRACTICE */
let plusTen = add(startingValue,10);
let double = multiply(plusTen,2);
let poundFormat = format(double);
let goodCode = poundFormat;

let 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
68 changes: 67 additions & 1 deletion extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { toBeOneOf } = require("jest-extended");
/**

Let's peer into the future using a Magic 8 Ball!
Expand Down Expand Up @@ -45,8 +46,34 @@

// This should log "The ball has shaken!"
// and return the answer.
let answers = [
"It is certain.",
"It is decidedly so.",
"Without a doubt.",
"Yes - definitely.",
"You may rely on it.",
"As I see it, yes.",
"Most likely.",
"Outlook good.",
"Yes.",
"Signs point to yes.",
"Reply hazy, try again.",
"Ask again later.",
"Better not tell you now.",
"Cannot predict now.",
"Concentrate and ask again.",
"Don't count on it.",
"My reply is no.",
"My sources say no.",
"Outlook not so good.",
"Very doubtful.",
];
let answer = "";

function shakeBall() {
//Write your code in here
console.log("The ball has shaken!");
return answer = answers[Math.floor(Math.random() * answers.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.

There's a lot going on in this line, could break it into several, similar to your 'good code' example above?

}

/*
Expand All @@ -58,10 +85,47 @@ function shakeBall() {

This function should expect to be called with any value which was returned by the shakeBall function.
*/
let positiveOrNegative = "";

function checkAnswer(answer) {
//Write your code in here
switch (answer) {
case "It is certain.":
case "It is decidedly so.":
case "Without a doubt.":
case "Yes - definitely.":
case "You may rely on it.":
positiveOrNegative = "very positive";
break;
case "As I see it, yes.":
case "Most likely.":
case "Outlook good.":
case "Yes.":
case "Signs point to yes.":
positiveOrNegative = "positive";
break;
case "Reply hazy, try again.":
case "Ask again later.":
case "Better not tell you now.":
case "Cannot predict now.":
case "Concentrate and ask again.":
positiveOrNegative = "negative";
break;
case "Don't count on it.":
case "My reply is no.":
case "My sources say no.":
case "Outlook not so good.":
case "Very doubtful.":
positiveOrNegative = "very negative";
break;
}
return positiveOrNegative;
}

// shakeBall();
// console.log(answer);
// checkAnswer("Very doubtful.");
// console.log(positiveOrNegative);
/*
==================================
======= TESTS - DO NOT MODIFY =====
Expand Down Expand Up @@ -101,7 +165,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: 8 additions & 5 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
// 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";
}

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

return "The total is total";
return "The total is " + total;
}


/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
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
Loading