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
11 changes: 11 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@


console.log("Hello world");
console.log("Hello world. I am learning programming and it is so much fun");
console.log("I have been exercising Java Script and we are in week 1.");
console.log("I am looking forward to learn more and more.");

//If I get rid of the quotation mark, I face a syntax error and following codes wont operate.

console.log(123);

//After fixing the quotation mark from the previous console.log, and console.log a number a number will appear in the terminal in yellow.
6 changes: 5 additions & 1 deletion exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Start by creating a variable `greeting`

var greeting = "Hello World";
console.log(greeting);
console.log(greeting);
console.log(greeting);

// all three results are shown as expected
2 changes: 1 addition & 1 deletion exercises/D-strings/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
In programming there are different _types of_ data. You've used one data type already: **string**.

Computers recognise strings as a sequence of characters but to humans, strings are simply lines of text.
Computers recognize strings as a sequence of characters but to humans, strings are simply lines of text.

```js
var message = "This is a string";
Expand Down
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`

var message = "This is a string. ";
console.log(message);
var typeOfMessage = typeof message;
console.log(typeOfMessage);
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`
var greetingStart = " Hello, my name is ";
var myName = "Pezhman";
var message = greetingStart + myName;

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

// EXERCISE ONE:

var myName = "Pezhman";
var myNameLength = myName.length;
var message =
"My name is " +
myName +
" and my name is " +
myNameLength +
" characters long.";
console.log(message);
20 changes: 19 additions & 1 deletion exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
const name = " Daniel ";
const myName = " Daniel ";
// first I wanted to know the length of the given name with space inside quotation mark
const nameLength = myName.length;
console.log(nameLength); //9

// I wanna use the .trim function to get rid of the unwanted space
const correctedName = myName.trim();
const correctedNameLength = correctedName.length;

console.log(correctedNameLength); //7

//Now I type the message

const message =
"My name is" +
myName +
"and my name is " +
correctedNameLength +
" characters long.";

console.log(message);
2 changes: 1 addition & 1 deletion exercises/G-numbers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Unlike strings, numbers do not need to be wrapped in quotes.
var age = 30;
```

You can use mathematical operators to caclulate numbers:
You can use mathematical operators to calculate numbers:

```js
var sum = 10 + 2; // 12
Expand Down
9 changes: 9 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents = 15;
let numberOfMentors = 8;
let total = numberOfStudents + numberOfMentors;

let percentageOfStudents = numberOfStudents / total;
let percentageOfMentors = numberOfMentors / total;

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

//percentage before rounding up and showing them in console
var percentageOfStudents = (numberOfStudents / total) * 100;
var percentageOfMentors = (numberOfMentors / total) * 100;

console.log(percentageOfStudents);
console.log(percentageOfMentors);

//Rounding up percentages and showing them on console
var roundPercStudents = Math.round(percentageOfStudents);
var roundPercMentors = Math.round(percentageOfMentors);
console.log(roundPercStudents);
console.log(roundPercMentors);

//Declaring sentences by a string variable and showing them to the console
const studentResult = "Percentage of students is: " + roundPercStudents;
const mentorsResult = "Percentage of mentors is: " + roundPercMentors;

console.log(studentResult);
console.log(mentorsResult);
2 changes: 1 addition & 1 deletion exercises/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; // complete the function here
}

var result = halve(12);
Expand Down
2 changes: 1 addition & 1 deletion exercises/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; // complete function here
}

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

// 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(num1, num2) {
return num1 / num2;
}
var result = divide(3, 4);

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

var greeting = createGreeting("Daniel");
function createGreeting(name) {
return name;
}
var greeting = "my name is: " + 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 add(num1, num2) {
return num1 + num2;
}

// Call the function and assign to a variable `sum`

var sum = add(13, 124); // Call the function and assign to a variable `sum`
console.log(sum);
5 changes: 4 additions & 1 deletion exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Declare your function here

function createLongGreeting(name, age) {
const greetings = `My name is ${name} and I'm ${age} years old.`;
return greetings;
}
const greeting = createLongGreeting("Daniel", 30);

console.log(greeting);
20 changes: 20 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,23 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

function shouty(mentor) {
var upperCaseMentor = mentor.toUpperCase();
return `HELLO ${upperCaseMentor}`;
}

var shoutyGreeting = shouty(mentor1);
console.log(shoutyGreeting);

var shoutyGreeting = shouty(mentor2);
console.log(shoutyGreeting);

var shoutyGreeting = shouty(mentor3);
console.log(shoutyGreeting);

var shoutyGreeting = shouty(mentor4);
console.log(shoutyGreeting);

var shoutyGreeting = shouty(mentor5);
console.log(shoutyGreeting);
13 changes: 8 additions & 5 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// 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;
}
totalNum = addNumbers(1, 2, 3);
console.log(totalNum);

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;

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) {
a * b * c;
return;
return a * b * c;
}

/*
Expand Down
4 changes: 3 additions & 1 deletion mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Add comments to explain what this function does. You're meant to use Google!

//this function chooses a random number below 1:
function getRandomNumber() {
return Math.random() * 10;
return Math.floor(Math.random() * 10);
}

// Add comments to explain what this function does. You're meant to use Google!
Expand Down
16 changes: 14 additions & 2 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
Sales tax is 20% of the price of the product.
*/

function calculateSalesTax() {}
function calculateSalesTax(price) {
return price * 0.2;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I wrote the same way as you, but I did not pass the test. So I had to calculated total price including the tax in this function calculateSalesTax(). I wrote: return 1.2 * price; and the test then passed.

}

//let percentage = calculateSalesTax(15);
//console.log(percentage);

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

console.log(calculateSalesTax(17.5));
console.log(addTaxAndFormatCurrency(17.5));

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