Skip to content
This repository was archived by the owner on Mar 14, 2023. 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
18 changes: 13 additions & 5 deletions week-1/Extra/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
// 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(firstName, age) {
return "Hello, my name is " + firstName + " and I am " + age + " years old";
}
console.log(introduceMe("Sonjide", 27));

//===============================//

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

// Use string interpolation here
return "The total is %{total}"
return `The total is ${total}`;
}
var result = getTotal(23, 5);
console.log(result);

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
13 changes: 9 additions & 4 deletions week-1/Extra/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
// 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();
}
console.log(trimWord(" CodeYourFuture "));

//======================================//

function getWordLength(word) {
return "word".length()
return word.length;
}

//==================================================//

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


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

Expand Down
6 changes: 4 additions & 2 deletions week-1/Extra/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// Add comments to explain what this function does. You're meant to use Google!
function getNumber() {
return Math.random() * 10;
return Math.random() * 10; // it returns a random integers in between 0 and 9 including both.
}

// Add comments to explain what this function does. You're meant to use Google!
function s(w1, w2) {
return w1.concat(w2);
return w1.concat(w2); // concat method helps to add two or more arrays, where in this case array "w1" and array "w2" are added.
}

function concatenate(firstWord, secondWord, thirdWord) {
// Write the body of this function to concatenate three words together.
return firstWord.concat(" ",secondWord," ",thirdWord);
// Look at the test case below to understand what this function is expected to return.
}
console.log(concatenate('code', 'your', 'future'));

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
10 changes: 8 additions & 2 deletions week-1/Extra/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(price) {
return price * 1.20;
}


/*
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(price) {
const decimalFormat = "£" + calculateSalesTax(price).toFixed(2);
return decimalFormat;
}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
8 changes: 6 additions & 2 deletions week-1/Extra/5-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(price) {
return price * 1.4;
}

/*
CURRENCY FORMATTING
Expand All @@ -15,7 +17,9 @@ 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(price) {
return (price * 5.7) - (0.01 * price * 5.7);
}

/* ======= 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: 20 additions & 8 deletions week-1/Extra/6-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,38 @@
the final result to the variable goodCode
*/

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

function multiply(x, y) {
return x * y;
}

function multiply() {
function format(number) {
return "£" + number;
}

}

function format() {

}
// Why can this code be seen as bad practice? Comment your answer.

const startingValue = 2

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
let badCode = format(multiply( add(startingValue,10),2));
// This is code is bad practice because all the functions are on line line wwhich gives the result but doesen't looks good.



/* BETTER PRACTICE */

let goodCode =

const result1 = add(startingValue, 10);
const result2 = multiply(result1, 2);
const result3 = format(result2);
let goodCode = result3;



/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
43 changes: 42 additions & 1 deletion week-1/Extra/7-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,59 @@ Very doubtful.

// This should log "The ball has shaken!"
// and return the answer.
const veryPositiveAnswers = ["It is certain",
"It is decidedly so.",
"Without a doubt",
"Yes - definitely",
"You may rely on it"];
const positiveAnswers = ["As I see it, yes",
"Most likely",
"Outlook good",
"Yes",
"Signs point to yes"];
const negativeAnswers = ["Reply hazy",
"try again",
"Ask again later",
"Better not tell you now",
"Cannot predict now"];
const veryNegativeAnswers = ["Concentrate and ask again",
"Don't count on it",
"My reply is no",
"My sources say no",
"Outlook not so good",
"Very doubtful"];

const answers = veryPositiveAnswers.concat(positiveAnswers, negativeAnswers, veryNegativeAnswers);

function shakeBall() {
}
console.log("The ball has shaken!");
const answer = answers[Math.floor(Math.random() * answers.length)];
return answer;
}
shakeBall();


// This function should say whether the answer it is given is
// - very positive
// - positive
// - negative
// - very negative
// This function should expect to be called with any value which was returned by the shakeBall function.

function checkAnswer(answer) {
if (veryPositiveAnswers.indexOf(answer) > -1) {
return "very positive";
} else if (positiveAnswers.indexOf(answer) > -1) {
return "positive";
} else if (negativeAnswers.indexOf(answer) > -1) {
return "negative";
} else {
return "very negative";
}
}



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

Expand Down
9 changes: 8 additions & 1 deletion week-1/Homework/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// Start by creating a variable `message`

console.log(message);
var firstName = "Suman";
var nameLength = firstName.length;
console.log(nameLength);

var messageStart = "My name is";
var message = `${messageStart} ${firstName} and my name is ${nameLength} charecters long.`;

console.log(message);
8 changes: 7 additions & 1 deletion week-1/Homework/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
const name = " Daniel ";
const firstName = " Danie ";
console.log(firstName.trim());
const nameLength = firstName.length;

const messageStart = "My name is";
const message = `${messageStart} ${firstName}and my name is ${nameLength} charecters long.`;
console.log(message);


4 changes: 3 additions & 1 deletion week-1/Homework/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@


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

var result = halve(12);

console.log(result);
3 changes: 2 additions & 1 deletion week-1/Homework/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);

console.log(result);
3 changes: 2 additions & 1 deletion week-1/Homework/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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 3 * 4;
}

// Assign the result of calling the function the variable `result`
Expand Down
4 changes: 3 additions & 1 deletion week-1/Homework/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(a, b) {
return 3 / 4 ;
}
var result = divide(3, 4);

console.log(result);
10 changes: 7 additions & 3 deletions week-1/Homework/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, greetingStart) {
var greeting = greetingStart + name;
console.log(greeting);

}
var resultGreeting = createGreeting("Daniel", "Hello, my name is ");

var greeting = createGreeting("Daniel");

console.log(greeting);
console.log(resultGreeting);
11 changes: 9 additions & 2 deletions week-1/Homework/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// Declare your function first

function sum(a, b) {
return a + b;
}
// Call the function and assign to a variable `sum`

console.log(sum);
var result = sum(13, 124);
console.log(result);




22 changes: 21 additions & 1 deletion week-1/Homework/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
// Declare your function here

const greeting = createLongGreeting("Daniel", 30);
// function greetingFcn(name, age) {
// const greeting = "Hello, my name is" + " " + name + " " + "and I'm " + age + " " + "years old.";
// return greeting;
// }
// console.log(greetingFcn("Daniel", 30));


function createLongGreeting(name, age) {
const greeting = "Hello, my name is" + " " + name + " " + "and I'm " + age + " " + "years old.";
return greeting;
}

const greeting = createLongGreeting("Daniel", 30);
console.log(greeting);









25 changes: 25 additions & 0 deletions week-1/Homework/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,28 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";


function toUpper(phrase) {
var upperCased = phrase.toUpperCase();
return upperCased;
}
function greetingFcn(name, greetingStart) {
// var greeting = greetingStart + " " + name;
var greeting = `${greetingStart} ${name}`;

// var upperGreeting = toUpper(greeting);

// return upperGreeting;
return toUpper(greeting);
}
var greetingStart = "hello";

console.log(greetingFcn(mentor1, greetingStart));
console.log(greetingFcn(mentor2, greetingStart));
console.log(greetingFcn(mentor3, greetingStart));
console.log(greetingFcn(mentor4, greetingStart));
console.log(greetingFcn(mentor5, greetingStart));



2 changes: 2 additions & 0 deletions week-1/InClass/exercise-A.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
console.log("Hello World")

Loading