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
3 changes: 3 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
console.log("Hello world");
console.log("Are you learning as well?");
console.log("I " + "hope " + "that you know " + "what you are doing.");
console.log(3);
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 = "Hello World";
console.log(greeting);
console.log(greeting);
console.log(greeting);
4 changes: 3 additions & 1 deletion exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `message`

var message = "This is a string";
console.log(message);
var messageType = typeof message;
console.log(messageType);
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`

var firstPart = "Hello, my name is ";
var secondPart = "Ro.";
var message = firstPart + secondPart;
console.log(message);
17 changes: 16 additions & 1 deletion exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// Start by creating a variable `message`

var name = "Daniel";
var nameLength = name.length;
var messagePart;
if (name.length === 1) {
var messagePart = "character";
} else {
var messagePart = "characters";
}
var message =
"My name is " +
name +
" and my name is " +
nameLength +
" " +
messagePart +
" long.";
console.log(message);
17 changes: 16 additions & 1 deletion exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
const name = " Daniel ";

var noSpaceName = name.trim();
var nameLength = noSpaceName.length;
var messagePart;
if (noSpaceName.length === 1) {
var messagePart = "character";
} else {
var messagePart = "characters";
}
var message =
"My name is " +
noSpaceName +
" and my name is " +
nameLength +
" " +
messagePart +
" long.";
console.log(message);
8 changes: 8 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
// 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)
);
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 total = numberOfStudents + numberOfMentors;
function percentageOf(num) {
var precisePercentage = (num / total) * 100;
let roughPercentage = Math.round(precisePercentage);
return roughPercentage;
}

console.log("Percentage students: " + percentageOf(numberOfStudents) + "%");
console.log("Percentage mentors: " + percentageOf(numberOfMentors) + "%");
1 change: 1 addition & 0 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function halve(number) {
return number / 2;
// complete the function here
}

Expand Down
1 change: 1 addition & 0 deletions exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function triple(number) {
return number * 3;
// complete function here
}

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,5 +1,6 @@
// Complete the function so that it takes input parameters
function multiply() {
function multiply(num1, num2) {
return num1 * num2;
// Calculate the result of the function and return it
}

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

function divide(num1, num2) {
return num1 / num2;
}
var result = divide(3, 4);

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

function createGreeting(name) {
return "Hello, my name is " + name;
}

var greeting = createGreeting("Daniel");

console.log(greeting);
4 changes: 4 additions & 0 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Declare your function first
function add(num1, num2) {
return num1 + num2;
}

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

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

const greeting = createLongGreeting("Daniel", 30);
function createLongGreeting(name, age) {
let ageGreet;
if (age === 1) {
ageGreet = "year";
} else {
ageGreet = "years";
}
return (
"Hello, my name is " + name + " and I'm " + age + " " + ageGreet + " old"
);
}

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

console.log(greeting);
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 shoutGreeting(name) {
return "HELLO " + name.toUpperCase();
}

console.log(shoutGreeting(mentor1));
console.log(shoutGreeting(mentor2));
console.log(shoutGreeting(mentor3));
console.log(shoutGreeting(mentor4));
console.log(shoutGreeting(mentor5));
11 changes: 8 additions & 3 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(num) {
return num * 1.4;
}

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

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.

To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 1-syntax-errors` into your terminal
To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 1-syntax-errors` correct path: `npm run extra-tests -- --testPathPattern 1-currency-conversion` into your terminal
(Reminder: You must have run `npm install` one time before this will work!)
*/

Expand Down
16 changes: 8 additions & 8 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@
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(24);

/* BETTER PRACTICE */

let goodCode =
let goodCode = format(24);

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



// This should log "The ball has shaken!"
// and return the answer.
function shakeBall() {

listOfAnswers = [
"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.",
];

var randomNumber = Math.floor(Math.random() * 20);

console.log("The ball has shaken!");

var answer = listOfAnswers[randomNumber];
return answer;
//Write your code in here
}

Expand All @@ -59,6 +91,17 @@ function shakeBall() {
This function should expect to be called with any value which was returned by the shakeBall function.
*/
function checkAnswer(answer) {
var shortMessage;
if (listOfAnswers.indexOf(answer) >= 0 && listOfAnswers.indexOf(answer) <= 4 ) {
shortMessage = "very positive";
} else if (listOfAnswers.indexOf(answer) >= 5 && listOfAnswers.indexOf(answer) <= 9) {
shortMessage = "positive";
} else if (listOfAnswers.indexOf(answer) >= 10 && listOfAnswers.indexOf(answer) <= 14) {
shortMessage = "negative";
} else if (listOfAnswers.indexOf(answer) >= 15 && listOfAnswers.indexOf(answer) <= 19) {
shortMessage = "very negative";
}
return shortMessage;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well done Roman, I like your code here, very clean, it was a slightly different approach than what I had done.

//Write your code in here
}

Expand Down Expand Up @@ -101,7 +144,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
11 changes: 6 additions & 5 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;
total = a + b;

return "The total is total";
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
5 changes: 5 additions & 0 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// Add comments to explain what this function does. You're meant to use Google!
/*The Math.random() function returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1) with approximately uniform distribution over that range — which you can then scale to your desired range. The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or reset by the user.*/
/*this function create random number, the result is random number time by 10*/
function getRandomNumber() {
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!
/*The concat() method concatenates the string arguments to the calling string and returns a new string.*/
/*this function is going to create connected word from word1 and word2 input*/
function combine2Words(word1, word2) {
return word1.concat(word2);
}

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

/*
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,10 @@
Sales tax is 20% of the price of the product.
*/

function calculateSalesTax() {}
function calculateSalesTax(num) {
let result = num + num * 0.2;
return result;
}

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

function addTaxAndFormatCurrency() {}
function addTaxAndFormatCurrency(num) {
let result = num + num * 0.2;
return "£" + result.toFixed(2);
}

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