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
4 changes: 4 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
console.log("Hello world");
console.log("i study in code your future");
console.log("hello" ,4 ," hello");
console.log('bbc');
console.log(544);
5 changes: 4 additions & 1 deletion 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: 2 additions & 1 deletion exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Start by creating a variable `message`

let message="this is a string"
console.log(message);
console.log(typeof message);
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 myName ="Bahare";
let message =greeting+myName;
console.log(message);
3 changes: 2 additions & 1 deletion exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Start by creating a variable `message`

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

let message="My name is "+name+" and my name is "+(name.trim()).length +" characters long"
console.log(message);
5 changes: 5 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents= 15;
let numberOfMentors= 8;
console.log("Number of students: " +numberOfStudents);
console.log("Number of mentors: "+numberOfMentors);
console.log("Total number of students and mentors: " +(numberOfStudents+numberOfMentors))
2 changes: 2 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
console.log("Percentage students: "+ Math.round((numberOfStudents*100)/(numberOfMentors+numberOfStudents))+"%");
console.log("Percentage mentors: "+ Math.round((numberOfMentors*100)/(numberOfMentors+numberOfStudents))+"%");
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
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, my name is "+name ;
}

var greeting = createGreeting("Daniel");

Expand Down
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 add (a,b){
return a+b;
}

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

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

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

console.log(greeting);
22 changes: 22 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,25 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";
function convertToUpperCase (name){
return name.toUpperCase()
}
function shoutyGreeting (mentor){
let upperCase=convertToUpperCase(mentor);
let greeting="Hello "+upperCase
return greeting;
}


console.log(shoutyGreeting(mentor1));
console.log(shoutyGreeting(mentor2));
console.log(shoutyGreeting(mentor3));
console.log(shoutyGreeting(mentor4));
console.log(shoutyGreeting(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 price*1.4;
}

/*
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 Number(((price*0.99)*5.7).toFixed(2));
}

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

function add() {

function add(num1,num2) {
return num1+num2;
}

function multiply() {

function multiply(num1,num2) {
return num1*num2;
}

function format() {
function format(num) {
return "£"+num;

}

const startingValue = 2;

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


/* BETTER PRACTICE */
//Just for fun,i dont know the better way to write that code:)

let goodCode =
let goodCode =format((startingValue+10)*2);

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
106 changes: 94 additions & 12 deletions extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**

Let's peer into the future using a Magic 8 Ball!
https://en.wikipedia.org/wiki/Magic_8-Ball
https://en.wikipedia.org/wiki/Magic_8-Ball

There are a few steps to being able view the future though:
* Ask a question
Expand All @@ -14,7 +14,7 @@

Below are the possible answers:

## Very positive
## Very positive
It is certain.
It is decidedly so.
Without a doubt.
Expand Down Expand Up @@ -45,11 +45,46 @@

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

const 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.",
],
];
console.log("The ball has shaken!");
return (answer =
answers[Math.floor(Math.random() * 4)][Math.floor(Math.random() * 5)]);
}

/*
/*
This function should say whether the answer it is given is
- very positive
- positive
Expand All @@ -60,9 +95,55 @@ function shakeBall() {
*/
function checkAnswer(answer) {
//Write your code in here
const 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.",
],
];

for (let i = 0; i < 4; i++) {
for (let j = 0; j < 5; j++) {
if (answers[i][j] === answer) {
if (i === 0) {
return "very positive";
} else if (i === 1) {
return "positive";
} else if (i === 2) {
return "negative";
} else {
return "very negative";
}
}
}
}
}

/*
/*
==================================
======= TESTS - DO NOT MODIFY =====

Expand All @@ -82,12 +163,11 @@ test("whole magic 8 ball sequence", () => {
expect(consoleLogSpy).toHaveBeenCalledTimes(1);
expect(consoleLogSpy).toHaveBeenLastCalledWith("The ball has shaken!");

expect(checkAnswer(answer)).toBeOneOf([
"very positive",
"positive",
"negative",
"very negative",
]);
expect(
["very positive", "positive", "negative", "very negative"].includes(
checkAnswer(answer)
)
).toEqual(true);
});

test("magic 8 ball returns different values each time", () => {
Expand All @@ -101,7 +181,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 All @@ -115,4 +197,4 @@ test("checkAnswer works for `It is decidedly so.`", () => {

test("checkAnswer works for `My reply is no.`", () => {
expect(checkAnswer("My reply is no.")).toEqual("very negative");
});
});
14 changes: 8 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){
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;
}

/*
Expand All @@ -19,7 +20,8 @@ function getTotal(a, b) {

There are some Tests in this file that will help you work out if your code is working.

To run the tests for just this one file, type `npm test -- --testPathPattern 1-syntax-errors` into your terminal
To run the tests for just this one file, type `
` into your terminal
(Reminder: You must have run `npm install` one time before this will work!)

===================================================
Expand Down
Loading