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
5 changes: 5 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
console.log("Hello world");

console.log (12345);
console.log ("Hello World I just started learning Jvascript");


3 changes: 3 additions & 0 deletions 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);
4 changes: 4 additions & 0 deletions exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Start by creating a variable `message`
let message = "This is a string in Javascript";
let messageType = typeof message;

console.log(message);
console.log(messageType);

7 changes: 6 additions & 1 deletion exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Start by creating a variable `message`
var greetingStart = "Hello, my name is ";
var name = "Karleen";
var greetingEnd = ", I'm glad you visited."

console.log(message);
var greeting = greetingStart + name + greetingEnd;

console.log(greeting);
13 changes: 13 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
var numberOfStudents = 15;
var numberOfMentors = 8;

const amtOfTrainees = "Number of trainees: ";
const numberOfTrainees = 36;

console.log (amtOfTrainees + numberOfTrainees);

const amtOfMentors = "Number of mentors: ";
const numberOfMentors = 10;

console.log (amtOfMentors + numberOfMentors);

const sum = 36 + 10;
console.log ("Total number of trainees and mentors: " + sum);
12 changes: 9 additions & 3 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
function halve(number) {
// complete the function here

function increaseByHalf(number) {
return number / 2 + number
}

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

var result = increaseByHalf(1000);
console.log(result);

var result = increaseByHalf(8500);
console.log(result);
15 changes: 13 additions & 2 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

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

console.log(convertToUSD(32));
console.log(convertToUSD(50));

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

console.log(convertToBRL(30));
console.log(convertToBRL(1.50));

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

function add() {

function add(a,b) {
return (a + b).toFixed(1);
}

function multiply() {
console.log(add(1,3));
console.log(add(2.4,5))

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

function format() {
console.log(multiply(2,3))

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

const startingValue = 2;
console.log(format(16));
console.log(format(10.1));

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

console.log(badCode);



/* BETTER PRACTICE */
let first = startingValue + 10;
let second = first * 2;
let goodCode = format(second);
Comment on lines +49 to +51

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 on getting onto this!


let goodCode =
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
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";
const total = a + b;
return "The total is " + total;
}

/*
Expand Down
8 changes: 4 additions & 4 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// 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
3 changes: 3 additions & 0 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
function getRandomNumber() {
return Math.random() * 10;
}
// The Math.random method returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1.

// Add comments to explain what this function does. You're meant to use Google!
function combine2Words(word1, word2) {
return word1.concat(word2);
}
//The .concat method joins two or more strings.

function concatenate(firstWord, secondWord, thirdWord) {
return firstWord.concat(" ",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.
}
Expand Down
16 changes: 13 additions & 3 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
Sales tax is 20% of the price of the product.
*/

function calculateSalesTax() {}

function calculateSalesTax(a) {

return (20 / 100 * a) + a;
}
console.log(calculateSalesTax(15));
console.log(calculateSalesTax(17.50));
console.log(calculateSalesTax(34));
/*
CURRENCY FORMATTING
===================
Expand All @@ -17,7 +22,12 @@ function calculateSalesTax() {}
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/

function addTaxAndFormatCurrency() {}
function addTaxAndFormatCurrency(b) {
return "£" + ((20 / 100 * b) + b).toFixed(2);
}
Comment on lines +25 to +27

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good use of .toFixed()

(20 / 100 * b) + b can be written as b * 1.2 but your version is better when the percentage is being passed in as a value eg 20

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi Pete, I'm not sure if I understand what you mean. Can you please explain this more. Should I change it to b * 1.2?

console.log(addTaxAndFormatCurrency(15));
console.log(addTaxAndFormatCurrency(17.50));
console.log(addTaxAndFormatCurrency(34));

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