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
120 changes: 120 additions & 0 deletions exercise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*function isEven (num) {
if (num%2 === 0)
return true;
else
return false;

}

console.log(isEven(235))*/

function isEven (num) {

}


/*function moreThanSixGoal (num1, num2) {
let total = num1 + num2;
if (total > 6)
return true;
else
return false;

}

console.log (moreThanSixGoal(2));
console.log (moreThanSixGoal(8));*/

/*
function numberChecker(num) {
if (num > 20) {
return `${num} is greater than 20`;
} else if (num === 20) {
return `${num} is equal to 20`;
} else if (num < 20) {
return `${num} is less than 20`;
} else {
return `${num} isn't even a number :(`;
}
}

console.log(numberChecker(10));
console.log(numberChecker(56));


function yourMood(message) {
if (message === "happy") {
return "Good job, you're doing great!";
} else if (message ==="sad") {
return "Every cloud has a silver lining";
} else if (typeof message === "number") {
return "Beep beep boop"
} else {
return "I'm sorry, I'm still learning about feelings!";
}
}

console.log(yourMood("happy"));
console.log(yourMood("sad"));
console.log (yourMood("sasdfasdf"));
*/

/*let num = 10
num > 5 && num < 15
num < 10 || num === 10
false || true
!true
let greaterThan5 = num > 5
!greaterThan5
!(num === 10)

function checkUsername (userName, userType) {
if (userName[0] === userName[0].toUppercase() && userName.length > 5 && userName < 10) {
return "Username valid";
} else if (userType === "admin" || userType === "manager") {
return "Username valid";
} else {
return "Username invalid";
}

}

console.log(checkUsername("Irina", "admin"));
*/

/*
const fruits = ["banana", "apple", "strawberry", "kiwi", "fig", "orange"];
console.log(fruits[2]);
console.log(fruits[3]);
console.log(fruits[5]);
console.log(fruits[0]);
console.log(fruits[-3]);
console.log(fruits[8]);

fruits[6] = "peach";

console.log(fruits);

fruits[10] = "pear";
console.log(fruits);
*/

const products = ["smart phones", "chargers", "laptops", "monitors", "printers", "keyboards", "mice"];

function numberOfProducts(products) {
return products.length;
}

function inStock(myProducts, nameOfProduct) {
for (let i = 0; i < myProducts.length; i++) {

if (nameOfProduct === myProducts[i]) {
return true
} else {
return false
}

}
}

console.log(inStock(products, "mice"));
4 changes: 4 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
console.log("Hello world");



console.log(12345);
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`

let 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`

let message = "This is a string";
console.log(message);
let messageType = typeof(message);
console.log(messageType);
3 changes: 3 additions & 0 deletions exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `message`
let greetingStart = "Hello! My name is ";
let myName = "Irina";
let message = greetingStart + myName;

console.log(message);
3 changes: 3 additions & 0 deletions exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `message`

let myName = "Irina";
let nameLength = myName.length;
let message = "Hello! My name is " + myName + " and my Name is " + nameLength + " characters long.";
console.log(message);
7 changes: 6 additions & 1 deletion exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const name = " Daniel ";

let message = "My name is " + name + " and my name is 6 characters long."
console.log(message);
let nameTrim = name.trim();

let message2 = "My name is " + nameTrim + " and my name is 6 characters long";
console.log(message2);

7 changes: 7 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents = 8;
let numberOfMentors = 15;
let totalNumber = numberOfMentors + numberOfStudents;

console.log("Number of students: " + numberOfStudents);
console.log("Number of mentors: " + numberOfMentors);
console.log("Total number of students and mentors " + totalNumber);
12 changes: 12 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
var numberOfStudents = 15;
var numberOfMentors = 8;

let totalNumber = numberOfMentors + numberOfStudents;

let percentOfStudents = numberOfStudents * 100 / totalNumber;
let percentOfMentors = numberOfMentors * 100 / totalNumber;



let roughPerSt = Math.round(percentOfStudents);
let roughPerMent= Math.round(percentOfMentors);
console.log("Percentage students: " + roughPerMent + "%");
console.log("Percentage mentors: " + roughPerSt + "%");
3 changes: 3 additions & 0 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
function halve(number) {
// complete the function here
return number / 2;
}

var result = halve(12);

console.log(result);
console.log(halve(6));

2 changes: 2 additions & 0 deletions exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
function triple(number) {
// complete function here
return number*3;
}

var result = triple(12);

console.log(result);
console.log(triple(5));
3 changes: 2 additions & 1 deletion exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Complete the function so that it takes input parameters
function multiply() {
function multiply(num1, num2) {
return num1 * num2;
// Calculate the result of the function and return it
}

Expand Down
3 changes: 3 additions & 0 deletions exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Declare your function first
function divide(a, b) {
return a/b;
}

var result = divide(3, 4);

Expand Down
3 changes: 3 additions & 0 deletions exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Write your function here
function createGreeting(name) {
return "Hello, my name is " + name;
}

var greeting = createGreeting("Daniel");

Expand Down
6 changes: 4 additions & 2 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Declare your function first

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

var sum = sumNumbers (13, 124);
console.log(sum);
5 changes: 5 additions & 0 deletions exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// Declare your function here
function createLongGreeting(name, age) {
return "Hello! My name is " + name + " and I am " + age + " years old.";
}



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

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


function greeting(name) {
let sayHello = "hello " + name;
return sayHello.toUpperCase();
}
console.log(greeting(mentor1));
console.log(greeting(mentor2));
console.log(greeting(mentor3));
console.log(greeting(mentor4));
console.log(greeting(mentor5));
11 changes: 9 additions & 2 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

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



/*
CURRENCY CONVERSION
Expand All @@ -15,7 +19,10 @@ 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) {
let newPrice = ((price * 99) / 100) * 5.7;
let brazilPrice = newPrice.toFixed(2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like the tests are failing here because this function is not returning a value. Any idea how you might fix 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
22 changes: 14 additions & 8 deletions extra/2-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(a, b) {
return a+b;
}

function multiply() {

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

function format() {

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

const startingValue = 2;

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
// too many functions, difficult to understand;
format (multiply(add(startingValue, 10), 2));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like the test is failing because we're not assigning a value to the variable badCode. Can you think of how to fix this?



/* BETTER PRACTICE */

let goodCode =
let sum = add(startingValue, 10);
let mult = multiply(sum, 2);


let goodCode = format(mult);

/* ======= 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: 7 additions & 5 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,16 +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;
let total = a + b;

return "The total is total";
return "The total is " + total;
}

/*
Expand Down
7 changes: 3 additions & 4 deletions mandatory/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 getStringLength(word) {
return "word".length();
return word.length;
}

function multiply(a, b, c) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you get a chance to look at this multiply function? It looks like you will still need to return a value here.

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.

Yes, now I fixed the errors

a * b * c;
return;
return a * b * c;
}

/*
Expand Down
Loading