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
Binary file added .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
console.log("Hello world");
console.log("Hello world. I just started learning JavaScript")
console.log("what happens when i get rid of the quote marks?")
console.log("syntax error will occur")
console.log(7)
console.log('it logs the number')

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'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This works fine, but if the value of greeting will only be set once and not changed later, const is better than let

console.log(greeting);
console.log(greeting);
console.log(greeting);
6 changes: 4 additions & 2 deletions 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`

console.log(message);
let message='lexi was doing the exercises'
let type=typeof message;
console.log(message)
console.log(type);
5 changes: 3 additions & 2 deletions exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Start by creating a variable `message`

console.log(message);
let firstName='lexi '
let lastName='Xing'
console.log(firstName + lastName);
4 changes: 3 additions & 1 deletion exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `message`
let name ="lexi";
let nameLength = name.length;

console.log(message);
console.log(name + nameLength);
3 changes: 2 additions & 1 deletion exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const name = " Daniel ";
const nameTrim=name.trim();

console.log(message);
console.log(nameTrim);
4 changes: 4 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents=15;
let numberOfMentors=8;
let total=numberOfMentors + numberOfStudents;
console.log(total)
7 changes: 7 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
var total=numberOfMentors + numberOfStudents;
var numberOfMen=Math.round((numberOfMentors/total)*100);
let perOfMen=numberOfMen + `%`;
var numberOfStu=Math.round((numberOfStudents/total)*100);
let perOfStu=numberOfStu + `%`;
console.log(perOfMen);
console.log(perOfStu);
1 change: 1 addition & 0 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function halve(number) {
// complete the function here
return number/2
}

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

var result = triple(12);

var result1 = triple(6);
var result = triple(2);
console.log(result1);
console.log(result);

3 changes: 2 additions & 1 deletion exercises/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 a*b
}

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

console.log(result);
4 changes: 3 additions & 1 deletion exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Write your function here

function createGreeting(name){
return ('nice to meet you ' + name)
}
var greeting = createGreeting("Daniel");

console.log(greeting);
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 summed(a,b) {
return a+b
}
// Call the function and assign to a variable `sum`

let sum = summed(13 + 24)
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'm ${age} years old`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great use of a template string

}



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

Expand Down
60 changes: 60 additions & 0 deletions exercises/L-functions-nested/even.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@



/*function moodChecker(mood) {
if (mood === "Happy") {
return 'good job, you are doing great';

} else if (mood === "sad") {
return "every cloud has a silver lining";
} else if (typeof mood === "number") {
return "beep beep boop";
} else {
return "i'm sorry, i'm still learning about feelings"
}
}
*/


// console.log(moodChecker("hmm"));

// && and
// || or
// ! not

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

console.log(checkUsername("lexi", "admin"));

const fruits = ['banana', 'apple', 'strawberry', 'kiwi', 'fig', 'orange'];
console.log(fruits[2], fruits[3]);

/*function lastTask (tasks) {
console.log(tasks[2]);
console.log(tasks.length);
return `don't forget to ${tasks[2].toUpperCase()}`
}



let tasks =['do the dishes', 'take out garbage', 'practice coding'];
console.log(lastTask(tasks)); */

function randomTask(tasks) {

}

let tasks = ['do the dishes', 'take out garbage',
'practice coding', 'clean house'];
console.log(randomTask['do the dishes', 'take out garbage',
'practice coding', 'clean house']);
15 changes: 14 additions & 1 deletion exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
var mentor1 = "Daniel";
var mentor1 = "Daniel! ";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";
function nameUpperCase (name) {
return name.toUpperCase();
}

function greetingMentors (name) {
return `hello ${nameUpperCase(name)}`;
}

console.log(greetingMentors(mentor1));
console.log(greetingMentors(mentor2));
console.log(greetingMentors(mentor3));
console.log(greetingMentors(mentor4));
console.log(greetingMentors(mentor5));
8 changes: 4 additions & 4 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";
return "Hello, my name is " + name + " and I am " + age + " years old";

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

return "The total is total";
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
10 changes: 10 additions & 0 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ function getRandomNumber() {
return Math.random() * 10;
}

// The Math object in JavaScript is a built-in object that has properties and methods for performing mathematical calculations.
// A common use of the Math object is to create a random number using the random() method.

// 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.

//The concat() method does not change the existing strings.

//The concat() method returns a new string.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍


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

/*
Expand Down
11 changes: 9 additions & 2 deletions mandatory/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(product) {
let incSalesTax=product*1.2;
return incSalesTax;
}

/*
CURRENCY FORMATTING
Expand All @@ -17,7 +20,11 @@ function calculateSalesTax() {}
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/

function addTaxAndFormatCurrency() {}
function addTaxAndFormatCurrency(currency) {
let first=calculateSalesTax(currency);
let second=first.toFixed(2);
return `£${second}`;
}

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