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: 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";
var messageType = typeof message;
console.log(message);
console.log(messageType);
6 changes: 4 additions & 2 deletions 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`

console.log(message);
var greetingPart1 = "Hello";
var greetingPart2 = "welcome to the world of programming!";
var name = "Bob";
console.log(greetingPart1 + " " + name + ", " + greetingPart2);
8 changes: 6 additions & 2 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`

console.log(message);
var sentencePart1 = "My name is";
var name = "Bob";
var sentencePart2 = "and my name is";
var nameLength = name.length;
var sentencePart3 = "characters long.";
console.log(sentencePart1 + " " + name + " " + sentencePart2 + " " + nameLength + " " + sentencePart3);
13 changes: 12 additions & 1 deletion exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
// Code that existed already
const name = " Daniel ";

console.log(message);
// Code written by me
// Variable initialization
var trimmedName = name.trim();
var sentencePart1 = "My name is";
var sentencePart2 = "and my name is";
var nameLength = trimmedName.length;
var sentencePart3 = "characters long.";

// Print the message on console
console.log(sentencePart1 + " " + trimmedName + " " + sentencePart2 + " " + nameLength + " " + sentencePart3);

8 changes: 4 additions & 4 deletions exercises/G-numbers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Unlike strings, numbers do not need to be wrapped in quotes.
var age = 30;
```

You can use mathematical operators to caclulate numbers:
You can use mathematical operators to calculate numbers:

```js
var sum = 10 + 2; // 12
Expand All @@ -17,13 +17,13 @@ var difference = 10 - 2; // 8

## Exercise

* Create two variables `numberOfStudents` and `numberOfMentors`
* Log a message that displays the total number of students and mentors
- Create two variables `numberOfStudents` and `numberOfMentors`
- Log a message that displays the total number of students and mentors

## Expected result

```
Number of students: 15
Number of mentors: 8
Total numnber of students and mentors: 23
Total number of students and mentors: 23
```
6 changes: 6 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
var numberOfStudents = 15;
var numberOfMentors = 8;
var total = numberOfStudents + numberOfMentors;
console.log("Number of students: " + numberOfStudents);
console.log("Number of mentors: " + numberOfMentors);
console.log("Total number of students and mentors: " + total);
10 changes: 10 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
// Variable initialization
var numberOfStudents = 15;
var numberOfMentors = 8;
var total = numberOfStudents + numberOfMentors;
var percentOfStudents = numberOfStudents / (total) * 100;
var percentOfMentors = numberOfMentors / (total) * 100;

// Print the message
console.log(`Percentage students: ${Math.round(percentOfStudents)}%`);
console.log(`Percentage mentors: ${Math.round(percentOfMentors)}%`);


7 changes: 6 additions & 1 deletion exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
function halve(number) {
// complete the function here
return number/2;
}

var result = halve(12);
console.log(result);

result = halve(23);
console.log(result);

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

var result = triple(12);

console.log(result);
4 changes: 2 additions & 2 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(num1, num2) {
return num1 * num2;
}

// Assign the result of calling the function the variable `result`
Expand Down
8 changes: 7 additions & 1 deletion exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Declare your function first
// function declaration
function divide(num1, num2)
{
return num1/num2;
}

// function call
var result = divide(3, 4);

// print the result
console.log(result);
6 changes: 5 additions & 1 deletion exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Write your function here
// function declaration
function createGreeting(name) {
message = "Hello, my name is " + name;
return message;
}

var greeting = createGreeting("Daniel");

Expand Down
7 changes: 6 additions & 1 deletion 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 declaration
function add(num1, num2) {
return num1 + num2;
}

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

// Print the result
console.log(sum);
6 changes: 5 additions & 1 deletion exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Declare your function here
// Function declaration
function createLongGreeting(name, age) {
message = "Hello, my name is " + name + " and I'm " + age + " years old";
return message;
}

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

Expand Down
2 changes: 1 addition & 1 deletion exercises/L-functions-nested/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function getAgeInDays(age) {
return age * 365;
}

function createCreeting(name, age) {
function createGreeting(name, age) {
var ageInDays = getAgeInDays(age);
var message =
"My Name is " + name + " and I was born over " + ageInDays + " days ago!";
Expand Down
26 changes: 21 additions & 5 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";
// function to calculate the percentage
function percentage(num, total) {
return (num / total * 100);
}

// function to create the message
function createMessage(memberType, percentage) {
message = `Percentage ${memberType}: ${Math.round(percentage)}%`;
return message;
}

// variable initialization
var numberOfStudents = 15;
var numberOfMentors = 8;
var total = numberOfStudents + numberOfMentors;
var percentOfStudents = percentage(numberOfStudents, total);
var percentOfMentors = percentage(numberOfMentors, total);

// print the results
console.log(createMessage("students", percentOfStudents));
console.log(createMessage("mentors", percentOfMentors));
24 changes: 24 additions & 0 deletions exercises/L-functions-nested/exercise2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// function to convert a word to uppercase
function toUpper(word) {
return word.toUpperCase();
}

// function to create the greeting
function createShoutyGreeting(name) {
var greeting = `HELLO ${toUpper(name)}`;
return greeting;
}

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

// print the results
console.log(createShoutyGreeting(mentor1));
console.log(createShoutyGreeting(mentor2));
console.log(createShoutyGreeting(mentor3));
console.log(createShoutyGreeting(mentor4));
console.log(createShoutyGreeting(mentor5));
10 changes: 7 additions & 3 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

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

/*
CURRENCY FORMATTING
===================
The business is now breaking into the Brazilian market
Write a new function for converting to the Brazilian real (exchange rate is 5.7 BRL to £)
Write a new function for converting to the Brazilian real (exchange rate is 5.643 BRL to £)
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(priceInPound) {
return priceInPound * 5.643;
}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
28 changes: 18 additions & 10 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(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 =

/* BETTER PRACTICE */
/*
This is a bad coding example because it is unreadable and confusing. Reading this bit of code is difficult. Calling a function, within a function call and so on can easily lead to errors.
*/
let badCode = format(multiply(add(startingValue, 10), 2));

let goodCode =
// BETTER PRACTICE
/*
This is considered a better practice because the complicated task has been broken down into small readable, easy to understand steps.
*/
let step1 = add(startingValue, 10);
let step2 = multiply(step1, 2);
let finalStep = format(step2);
let goodCode = finalStep;

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
41 changes: 40 additions & 1 deletion extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,19 @@
// This should log "The ball has shaken!"
// and return the answer.
function shakeBall() {
//Write your code in here

// Array containing all the possible answers
let possibleAnswers = ["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."];

// Generate a random number to chose an answer from array of answers
let tempIndex = Math.random()*(possibleAnswers.length - 1);

// round the value of index to nearest whole number
let index = Math.round(tempIndex);

// log the message and return the randomly selected answer
console.log("The ball has shaken!");
return possibleAnswers[index];
}

/*
Expand All @@ -60,6 +72,32 @@ function shakeBall() {
*/
function checkAnswer(answer) {
//Write your code in here
let result;
switch(answer)
{
case "It is certain." :
case "It is decidedly so." :
case "Without a doubt." :
case "Yes - definitely." :
case "You may rely on it." : result = "very positive"; break;
case "As I see it, yes." :
case "Most likely." :
case "Outlook good." :
case "Yes." :
case "Signs point to yes." : result = "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." : result = "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." : result = "very negative"; break;
default : break;
}
return result;
}

/*
Expand All @@ -72,6 +110,7 @@ To run these tests type `node 3-magic-8-ball.js` into your terminal
==================================
*/


const log = console.log;
let logged;
console.log = function () {
Expand Down
12 changes: 6 additions & 6 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// 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;

return "The total is total"
total = a + b;
return "The total is " + total;
}

/*
Expand Down
Loading