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
11 changes: 6 additions & 5 deletions week-1/Extra/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// 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;

// Use string interpolation here
return "The total is %{total}"
return `The total is ${total}`
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
7 changes: 3 additions & 4 deletions week-1/Extra/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 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 =====
Expand Down
4 changes: 4 additions & 0 deletions week-1/Extra/3-function-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
function getNumber() {
return Math.random() * 10;
}
// Math.random returns a random number between 0 (inclusive), and 1 (exclusive). But, in this case, this number will be multiplied by 10. Then this function will return a number between 0 and 10(exclusive).


// Add comments to explain what this function does. You're meant to use Google!
function s(w1, w2) {
return w1.concat(w2);
}
// return new element with w1 and w2 concatenated.

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);
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
11 changes: 9 additions & 2 deletions week-1/Extra/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
Sales tax is 20% of the price of the product
*/

function calculateSalesTax() {}
function calculateSalesTax(originalPrice) {
let tax = originalPrice*0.2;
let taxPrice = originalPrice+tax;
return taxPrice;
}

/*
CURRENCY FORMATTING
Expand All @@ -17,7 +21,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) {
let decimalPrice = calculateSalesTax(price).toFixed(2);
return `£${decimalPrice}`;
}

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

function add() {

function add(x,y) {
return x+y;
}

function multiply() {

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

function format() {

function format(x) {
return `£${x.toString()}`
}

const startingValue = 2

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
let badCode = format((startingValue+10)*2);

/* BETTER PRACTICE */

let goodCode =
function toGoodCode(number) {
let operation = (number+10)*2;
let resultFormated = format(operation);
return resultFormated;
}

let goodCode = toGoodCode(startingValue);

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
3 changes: 3 additions & 0 deletions week-1/Extra/7-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Very doubtful.
// This should log "The ball has shaken!"
// and return the answer.
function shakeBall() {
console.log(`The ball has shaken!`)
return `It is certain.`;
}

// This function should say whether the answer it is given is
Expand All @@ -55,6 +57,7 @@ function shakeBall() {
// - very negative
// This function should expect to be called with any value which was returned by the shakeBall function.
function checkAnswer(answer) {

}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
10 changes: 9 additions & 1 deletion week-1/Homework/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// Start by creating a variable `message`
// let message = 'Amanda'
// console.log(message);

function lengthMessage(message) {
let lengthMessage = message.length;
console.log(`My name is ${message} ant the length of my name is ${lengthMessage}.`);
}

lengthMessage("amanda");

console.log(message);
10 changes: 8 additions & 2 deletions 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 names = " Amanda ";
const nameWithTrim = names.trim();
let lengthNames = names.length;
console.log(names);
console.log(nameWithTrim);

console.log(`My name is ${nameWithTrim} ant the length of my name is ${lengthNames}.`)


console.log(message);
2 changes: 1 addition & 1 deletion week-1/Homework/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function halve(number) {
// complete the function here
return number/2
}

var result = halve(12);
Expand Down
2 changes: 1 addition & 1 deletion week-1/Homework/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function triple(number) {
// complete function here
return number*3
}

var result = triple(12);
Expand Down
19 changes: 12 additions & 7 deletions week-1/Homework/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// Complete the function so that it takes input parameters
function multiply() {
// Calculate the result of the function and return it
}
// // Complete the function so that it takes input parameters
// function multiply(x,y) {
// return x*y
// }

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

// console.log(result);

const arrowMultiply = (x, y) => x*y;

console.log(arrowMultiply(3,4));

console.log(result);
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,4 +1,6 @@
// Declare your function first
function divide(x,y) {
return x/y
}

var result = divide(3, 4);

Expand Down
5 changes: 3 additions & 2 deletions week-1/Homework/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Write your function here

function createGreeting(name) {
return `Hello ${name}, good night! I need to sleep.`
}
var greeting = createGreeting("Daniel");

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

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

console.log(sum);
6 changes: 4 additions & 2 deletions week-1/Homework/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// 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);
const greeting = createLongGreeting("Amanda", 33);

console.log(greeting);
41 changes: 36 additions & 5 deletions week-1/Homework/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";
var mentor1 = "Lucia";
var mentor2 = "Giorgio";
var mentor3 = "Fred";
var mentor4 = "Ananda";
var mentor5 = "Ali";

function upperCase(mentor) {
return mentor.toUpperCase();

}

// let mentorUpper = upperCase(mentor1);
// console.log(mentorUpper);


// function greeting(mentor){
// let mentorUpper = upperCase(mentor);
// console.log(`HELLO ${mentorUpper}`);
// // return `HELLO ${mentorUpper}`
// }

// best way""

function greeting(mentor){
console.log(`HELLO ${upperCase(mentor)}`);
}


// let hello = greeting(mentor1)
// console.log(hello);

greeting(mentor1);
greeting(mentor2);
greeting(mentor3);
greeting(mentor4);
greeting(mentor5);
1 change: 1 addition & 0 deletions week-1/InClass/exercise-A.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello World!!!")
10 changes: 10 additions & 0 deletions week-1/InClass/exercise-B.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
console.log("Hello, world!")
console.log("Halo, dunia!")
console.log("Ciao, mundo!")
console.log("Olá, mundo!")
console.log("Hola, mundo!")
console.log("Hallo Welt")
console.log("Zdravo svijete")
console.log("Dia duit Domhanda")
console.log("Hola món")
console.log("مرحبا بالعالم")
5 changes: 5 additions & 0 deletions week-1/InClass/exercise-C.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let greeting = "great day"

console.log(greeting);
console.log(greeting);
console.log(greeting);
7 changes: 7 additions & 0 deletions week-1/InClass/exercise-D.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let colors = "blue, yellow";
console.log(colors);

let numQuatro = 4;

console.log("The datatype of numQuatro is: " + typeof numQuatro);
console.log("The datatype of colors is: " + typeof colors);
8 changes: 8 additions & 0 deletions week-1/InClass/exercise-E.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const nome = "Amanda!";
const greetingStart = "Hi, my name is ";

const greeting = greetingStart + nome;
console.log(greeting);

const newGreeting = `${greetingStart}, ${nome} and I'm linda!`
console.log(newGreeting);
7 changes: 7 additions & 0 deletions week-1/InClass/exercise-F.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const numberOfStudents = 15;
const numberOfMentors = 1;
let totalNumber = numberOfStudents + numberOfMentors;

console.log(`Number of students: ${numberOfStudents}`);
console.log(`Number of mentors: ${numberOfMentors}`);
console.log(`Total number of students and mentors: ${totalNumber}`);
9 changes: 9 additions & 0 deletions week-1/InClass/exercise-G.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const numberOfStudents = 15;
const numberOfMentors = 1;
let totalNumber = numberOfStudents + numberOfMentors;

const percentageStudents = `Percentage students: ${Math.round((numberOfStudents/totalNumber)*100)}%`;
const percentageMentors = `Percentage mentors: ${Math.round((numberOfMentors/totalNumber)*100)}%`;

console.log(percentageStudents);
console.log(percentageMentors);
13 changes: 13 additions & 0 deletions week-1/InClass/exercise-H.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function exerciseH(num1, num2) {
let string = "The correct";
return `${string} sum of two numbers is: ${num1 + num2}`;
}
// I created a function that receive two number and do a operation. And I created a variavle inside my function who has a string. Then I concatanate the string and operation to return.


let result = exerciseH(5,10);
// To read my function's return, I had to store this value on ohter variable (result). Then, to see on console, I used console.log(result).

console.log(result);

// the diference between console.log and return is the console.log show the result without store this value on variable. But if I want use this result in another part of my code, I have to use "return".
11 changes: 11 additions & 0 deletions week-1/InClass/exercise-I.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function calculateYear(name, age){
let calculate = 2022 - age;
return `${name}, you were born in ${calculate}.`;
}

// first option
let year = calculateYear("Maria", 33);
console.log(year);

// second option
console.log(calculateYear("Joao", 40));
Loading