Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
Closed
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("Hello world. I just started learning JavaScript.");
console.log("My name is Amarachi. I am a Code Your Future Trainee.")
console.log("I am happy");
console.log(2);
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";
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`

const greeting = " Hello, my name is ";
const myName = "Amarachi";
const message = greeting + myName;
console.log(message);
16 changes: 14 additions & 2 deletions exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
// Start by creating a variable `message`

console.log(message);
// let myName = "Amarachi";
// myName = myName.length;
// console.log(myName);
// let myMessage = "My name is ";
// let myName = "Amarachi";
// let secondMessage = " and my name is ";
// let nameLength = myName.length;
// let thirdMessage = " characters long"
// let message = myMessage + myName + secondMessage + nameLength + thirdMessage;
// console.log(message);
let myName = "Amarachi";
let nameLength = myName.length;
let message = `My name is ${myName} and my name is ${nameLength} characters long`;
console.log(message);
3 changes: 3 additions & 0 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const name = " Daniel ";
const nameTrim = name.trim();
const nameLength = nameTrim.length;
const message = `My name is ${nameTrim} and my name is ${nameLength} characters long`

console.log(message);
4 changes: 4 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents = 20;
let numberOfMentors = 13;
let totalNumber = numberOfStudents + numberOfMentors;
console.log(totalNumber);
13 changes: 11 additions & 2 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;
// var numberOfStudents = 15;
// var numberOfMentors = 8;
// var totalNumber = numberOfStudents + numberOfMentors;
// var percentStudents = numberOfStudents * 100 / totalNumber;
// console.log(Math.round(percentStudents));

let numberOfStudents = 15;
let numberOfMentors = 8;
let totalNumber = numberOfStudents + numberOfMentors;
let percentMentors = (numberOfMentors * 100) / totalNumber;
console.log(Math.round(percentMentors));
3 changes: 2 additions & 1 deletion exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function halve(number) {
// complete the function here
return number / 2;
}

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

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

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

console.log(result);
5 changes: 3 additions & 2 deletions exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// 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`
var result = multiply(3, 4);
let result = multiply(3, 4);

console.log(result);
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) {
return a / b;
}

var result = divide(3, 4);
let result = divide(3, 4);

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

var greeting = createGreeting("Daniel");
function createGreeting(string) {
return ("Hello, my name is " + string);
}
let 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 add(a, b) {
return a + b;
}
// Call the function and assign to a variable `sum`
let sum = add(13, 124);

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, num) {
return ("Hello, my name is " + name + " and I'm " + num + " years old");
}

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

Expand Down
28 changes: 23 additions & 5 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";
// var mentor1 = "Daniel";
// var mentor2 = "Irina";
// var mentor3 = "Mimi";
// var mentor4 = "Rob";
// var mentor5 = "Yohannes";
function shoutyGreeting(name) {
return ("Hello " + name);
}
let mentor1 = shoutyGreeting("Daniel");
console.log(mentor1.toUpperCase());

let mentor2 = shoutyGreeting("Irina");
console.log(mentor2.toUpperCase());

let mentor3 = shoutyGreeting("Mimi");
console.log(mentor3.toUpperCase());

let mentor4 = shoutyGreeting("Rob");
console.log(mentor4.toUpperCase());

let mentor5 = shoutyGreeting("Yohannes");
console.log(mentor5.toUpperCase());

22 changes: 19 additions & 3 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

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

}
let myNum = convertToUSD(32);
console.log(myNum);

myNum = convertToUSD(50);
console.log(myNum);

/*
CURRENCY CONVERSION
Expand All @@ -15,12 +23,20 @@ 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(number) {
return parseFloat(((number * 99 / 100) * 5.7).toFixed(2));
}

let myConvert = convertToBRL(30);
console.log(myConvert);

myConvert = convertToBRL(1.5);
console.log(myConvert);

/* ======= TESTS - DO NOT MODIFY =====
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-currency-conversion` 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
31 changes: 26 additions & 5 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,47 @@
the final result to the variable goodCode
*/

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

}

function multiply() {
let num = add(1, 3);
console.log(num);

num = add(2.4, 5);
console.log(num);

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

}

function format() {
let myNum = multiply(2, 3);
console.log(myNum);

function format(number) {
return `£${number}`;
}

let myInt = format(16);
console.log(myInt);

myInt = format(10.1);
console.log(myInt);

const startingValue = 2;

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

/* BETTER PRACTICE */
let addBetter = add(10, startingValue);
let multiplyBetter = multiply(2, addBetter);
let formatBetter = format(multiplyBetter);

let goodCode =
let goodCode = formatBetter;
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
40 changes: 36 additions & 4 deletions extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@

Below are the possible answers:

## Very positive
## Very positive
It is certain.
It is decidedly so.
Without a doubt.
Yes - definitely.
You may rely on it.


## Positive
As I see it, yes.
Expand All @@ -42,13 +43,42 @@
Outlook not so good.
Very doubtful.
*/

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

const positive = [
'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.',];

const myAnswer = [...veryPositive, ...positive, ...negative, ...veryNegative,];
// This should log "The ball has shaken!"
// and return the answer.
function shakeBall() {
//Write your code in here
}
console.log("The ball has shaken!");

return myAnswer[Math.round(Math.random() * myAnswer.length)];
}
/*
This function should say whether the answer it is given is
- very positive
Expand Down Expand Up @@ -101,7 +131,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
16 changes: 9 additions & 7 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// 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";
}
let greet = introduceMe("Sonjide", 27);
console.log(greet);

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

return "The total is total";
return "The total is " + (a + b);
}

let result = getTotal(14, 14);
console.log(result);
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
Loading