Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
Closed
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 World. I just started learning JavaScript!');
4 changes: 2 additions & 2 deletions exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Start by creating a variable `greeting`

console.log(greeting);
var greeting = "Hello world\n"; // added backspace \n newline
console.log(greeting.repeat(3)); // added repeat 3
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 stringType = typeof message;
console.log(message);
console.log(stringType);
4 changes: 4 additions & 0 deletions exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Start by creating a variable `message`
var greetingStart = "Hello, my name is ";
var name = "Jay!";

var message = greetingStart + name;

console.log(message);
5 changes: 5 additions & 0 deletions exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Start by creating a variable `message`
var name = "Jonathan"; // 8 letters
var nameLength = name.length;
var greetingStart = "Hello, my name is Jonathan and my name is " + nameLength + " letters long.";
var message = greetingStart;


console.log(message);
9 changes: 7 additions & 2 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const name = " Daniel ";
var name = " Daniel "; // 6 letters long
var nameTrim = name.trim(); // need to trim the string first!
var nameTrimLength = nameTrim.length;
var greetingStart = "Hello, my name is Daniel and my name is ";
var greetingEnd = " letters long.";

console.log(message);

console.log(greetingStart + nameTrimLength + greetingEnd );
19 changes: 19 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`

//Create two variables `numberOfStudents` and `numberOfMentors`
//Log a message that displays the total number of students and mentors
//Number of students: 15
//Number of mentors: 8
//Total number of students and mentors: 23


var numberOfStudents = "Number of students: ";
var numberOfMentors = "Number of mentors: ";
var numberOfStudentsMentors = "Total number of students and mentors:";
var students = 30;
var mentors = 5;
var totalClass = students + mentors; // 35

console.log(numberOfStudents + students);
console.log(numberOfMentors + mentors);
console.log(numberOfStudentsMentors + totalClass);

20 changes: 20 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
//Percentage students: 65%
//Percentage mentors: 35%


var numberOfStudents = 15;
var numberOfMentors = 8;
var studentsPer = "Percentage students: ";
var mentorsPer = "Percentage mentors: ";
var per = "%"
var total = numberOfStudents + numberOfMentors; // 23
//function for percentage
function percentage (x,y) {
return x/y*100;

};
var perRoundStud = Math.round(percentage(numberOfStudents,total)); // rounded up
var perRoundMentor = Math.round(percentage(numberOfMentors,total)); // rounded up

console.log(studentsPer + percentage(numberOfStudents,total) + per);
console.log(mentorsPer + percentage(numberOfMentors,total) + per );
console.log(studentsPer + perRoundStud + per); // round down
console.log(studentsPer + perRoundMentor + per); // round up
18 changes: 16 additions & 2 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@

//Complete the function in exercise.js so that it halves the input

//Try calling the function more than once with some different numbers

// Remember to use the return keyword to get a value out of the function





function halve(number) {
// complete the function here
return number/2;
}

var result = halve(12);
var result2 = halve(50);


console.log(result);
console.log(result); // half 12 = 6
console.log(result2); // half 50 = 25
7 changes: 6 additions & 1 deletion exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

//Complete the function in exercise2.js so that it triples the input


function triple(number) {
// complete function here
return number*3;
}

var result = triple(12);
var result = triple(12); // 12 x 3 = 36

console.log(result);
15 changes: 13 additions & 2 deletions exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@

//Write a function that multiplies two numbers together




// Complete the function so that it takes input parameters
function multiply() {
function multiply(num1,num2) {
// Calculate the result of the function and return it
return num1 * num2;

}

// Assign the result of calling the function the variable `result`
var result = multiply(3, 4);
var result2 = multiply(6, 9);

console.log(result); // 12 3x4=12
console.log(result2); // 54 6x9=54

console.log(result);
10 changes: 9 additions & 1 deletion exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
// Declare your function first
//From scratch, write a function that divides two numbers

function divide (num1,num2) {
return num1/num2;
}


var result = divide(3, 4);
var result2 = divide(100, 3);

console.log(result);
console.log(result); // output 0.75
console.log(Math.round(result2)); // rounded to 33 for 33.33333
13 changes: 12 additions & 1 deletion exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
// Write your function here
//Write a function that takes a name (a string) and returns a greeting

var greeting = createGreeting("Daniel");
var daniel ="Daniel";
var susan ="Susan";
var end = "!";
function createGreeting (name) {

return "Hello, my name is " + name + end;
}


var greeting = createGreeting(daniel);// added val Daniel
var greeting = createGreeting(susan); // replaces Daniel with susan

console.log(greeting);
9 changes: 9 additions & 0 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@

//Write a function that adds two numbers together
//Call the function, passing `13` and `124` as parameters, and assigning the returned value to a variable `sum`


// Declare your function first
function addition (num1,num2){
return num1+num2;
}

// Call the function and assign to a variable `sum`
var sum = addition(13,124); // 13+124 = 134

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

//Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string)

//## Expected result

//Hello, my name is Daniel and I'm 30 years old





// 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);
31 changes: 26 additions & 5 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

//Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string)

// ## Expected result

//Hello, my name is Daniel and I'm 30 years old



// main function
function createGreeting (name,age){
return "Hello, my name is " + name + " and I'm " + age + " years old"
}
// array of names
var array1 = ["Daniel","Irina","Mimi","Rob",
"Yohannes"];

function randomAge (min,max){
return Math.random() * (min + max) + min;
}
var random = array1[Math.floor(Math.random()*array1.length)]; // picks names from array
var ages = randomAge(10 , 60); // randoms age
var agesRound = Math.round(ages); // rounds age
const greeting = createGreeting(random,agesRound);

console.log(greeting);
12 changes: 8 additions & 4 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(GDP) {
return GDP * 1.4;
}

/*
CURRENCY FORMATTING
/*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 £)
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(BRL) {

return BRL/100*99* 5.7; // 99% of BRL X 5.7 = pounds
}

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

function add() {

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

function multiply() {

function multiply(c,d) {
var multiplyTotal = c * d;
return multiplyTotal;
}

function format() {

function format(num1) {
return "£" + num1;
}

const startingValue = 2
const startingValue = 2;
let addedTotal = add(startingValue, 10);
let multiTotal = multiply(addedTotal, 2);

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

//looks messy hard to unerstand unsure if this is the right way???

/* BETTER PRACTICE */

let goodCode =
let goodCode = format(multiTotal);
// more layed out. maybe a easier way to do this

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

}

console.log(shakeBall);
/*
This function should say whether the answer it is given is
- very positive
Expand All @@ -60,8 +62,18 @@ function shakeBall() {
*/
function checkAnswer(answer) {
//Write your code in here
var array1 = ["very positive" , "positive" , "negative" , "very negative"];
var random = array1[Math.floor(Math.random()*array1.length)]; // picks names from array
//var veryPos = ["It is certain" , "It is decidedly so" , "Without a doubt" , "Yes - definitely" ,"You may rely on it"];
//var randomVP = veryPos[Math.floor(Math.random()*veryPos.length)]; // picks names from array
//var pos = [ "As I see it, yes" , "Most likely" , "Outlook good" , "Yes" ,"Signs point to yes"];
//var negative =[];
//var very negative = [];

return random;
}


/*
==================================
======= TESTS - DO NOT MODIFY =====
Expand Down
27 changes: 20 additions & 7 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
// There are syntax errors in this code - can you fix it to pass the tests?

function addNumbers(a b c) {

//Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string)

//## Expected result





// There are syntax errors in this code - can you fix it to pass the tests?
// addNumber adds a,b,c missing comma's
function addNumbers(a , b , c) {
return a + b + c;
}
// introduce adds a string with age and name missing + , missing curly brackets, added spaces
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";

// getTotal adds a,b
//removed a + (was a ++ b)
function getTotal(a, b) {
total = a ++ b;
return "The total is " + (a+b);


return "The total is total"
}

/*
Expand Down
Loading