Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Week 3 #96

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion week-1/1-exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
console.log("Hello world");
console.log("Hello world. I just started learning JavaScript!.");
console.log("My name is Osman.");
console.log("I'm " + 27 + " years old.");
4 changes: 3 additions & 1 deletion week-1/1-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);
3 changes: 2 additions & 1 deletion week-1/1-exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Start by creating a variable `message`

let message = "This is a string";
console.log(message);
console.log(typeof message);
6 changes: 4 additions & 2 deletions week-1/1-exercises/E-strings-concatenation/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 name = "Osman.";
let greeting = "Hello, my name is ";
let introduction = greeting + name;
console.log(introduction);
7 changes: 5 additions & 2 deletions week-1/1-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`

console.log(message);
let name = "Osman";
let nameLength = name.length;
console.log(
"My name is " + name + "and my name is " + nameLength + " characters long"
);
13 changes: 10 additions & 3 deletions week-1/1-exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
const name = " Daniel ";

console.log(message);
let name = " Daniel ";
let nameTrim = name.trim();
let lengthOfName = nameTrim.length;
console.log(
"My name is " +
name.trim() +
" and my name is " +
lengthOfName +
" characters long."
);
6 changes: 6 additions & 0 deletions week-1/1-exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents = 15;
let numberOfMentors = 8;
let sum = numberOfStudents + numberOfMentors;
console.log("Number of students: " + numberOfStudents);
console.log("Number of mentors: " + numberOfMentors);
console.log("Total number of students and mentors: " + sum);
5 changes: 5 additions & 0 deletions week-1/1-exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
let sum = numberOfStudents + numberOfMentors;
let studentsPercentage = Math.round((numberOfStudents / sum) * 100);
let mentorsPercentage = Math.round((numberOfMentors / sum) * 100);
console.log("Percentage students: " + studentsPercentage + "%");
console.log("Percentage mentors: " + mentorsPercentage + "%");
11 changes: 8 additions & 3 deletions week-1/1-exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
function halve(number) {
// complete the function here
// complete the function here
return number / 2;
}

var divide = halve(65);
var result = halve(12);

var num = halve(109);
var output = halve(34);
console.log(divide);
console.log(result);
console.log(num);
console.log(output);
1 change: 1 addition & 0 deletions week-1/1-exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function triple(number) {
// complete function here
return number * 3;
}

var result = triple(12);
Expand Down
5 changes: 3 additions & 2 deletions week-1/1-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() {
// Calculate the result of the function and return it
function multiply(num1, num2) {
// Calculate the result of the function and return it
return num1 * num2;
}

// Assign the result of calling the function the variable `result`
Expand Down
4 changes: 3 additions & 1 deletion week-1/1-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);
4 changes: 3 additions & 1 deletion week-1/1-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 "Hello, my name is " + name;
}
var greeting = createGreeting("Daniel");

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

let sum = add(13, 124);
console.log(sum);
4 changes: 3 additions & 1 deletion week-1/1-exercises/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);

console.log(greeting);
7 changes: 7 additions & 0 deletions week-1/1-exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
let studentsNumber = 15;
let mentorsNumber = 8;
let sum = studentsNumber + mentorsNumber;
function percentage(prcntg){
return Math.round(prcntg / sum * 100);
}
function getPrcentage()
var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
Expand Down
51 changes: 28 additions & 23 deletions week-1/2-mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@


// There are syntax errors in this code - can you fix it to pass the tests?

function addNumbers(a b c) {
return 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 getAddition(a, b) {
total = a ++ b
function introduceMe(name, age) {
return "Hello, my name is " + name + " and I am " + age + " years old";
}
function getRemainder(a, b) {
let total = a % b;

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

/* ======= TESTS - DO NOT MODIFY ===== */
//
//
// To run these tests type `node 1-syntax-errors.js` into your terminal

function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED"
} else {
status = "FAILED"
}

console.log(`${test_name}: ${status}`)
let status;
if (expr) {
status = "PASSED";
} else {
status = "FAILED";
}

console.log(`${test_name}: ${status}`);
}

test("fixed addNumbers function - case 1", addNumbers(3,4,6) === 13)
test("fixed introduceMe function", introduceMe("Sonjide",27) === "Hello, my name is Sonjide and I am 27 years old")
test("fixed getRemainder function", getRemainder(23,5) === "The remainder is 3")
test("fixed addNumbers function - case 1", addNumbers(3, 4, 6) === 13);
test(
"fixed introduceMe function",
introduceMe("Sonjide", 27) ===
"Hello, my name is Sonjide and I am 27 years old"
);
test(
"fixed getRemainder function",
getRemainder(23, 5) === "The remainder is 3"
);
35 changes: 20 additions & 15 deletions week-1/2-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 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 All @@ -20,16 +19,22 @@ To run these tests type `node 2-logic-error` into your terminal
*/

function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED"
} else {
status = "FAILED"
}

console.log(`${test_name}: ${status}`)
let status;
if (expr) {
status = "PASSED";
} else {
status = "FAILED";
}

console.log(`${test_name}: ${status}`);
}

test("fixed trimWord function", trimWord(" CodeYourFuture ") === "CodeYourFuture")
test("fixed wordLength function", getWordLength("A wild sentence appeared!") === 25)
test("fixed multiply function", multiply(2,3,6) === 36)
test(
"fixed trimWord function",
trimWord(" CodeYourFuture ") === "CodeYourFuture"
);
test(
"fixed wordLength function",
getWordLength("A wild sentence appeared!") === 25
);
test("fixed multiply function", multiply(2, 3, 6) === 36);
39 changes: 22 additions & 17 deletions week-1/2-mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// Add comments to explain what this function does. You're meant to use Google!
// a function with no parameters passed. The function is to multiply the given value with 10.
function getNumber() {
return Math.random() * 10;
// It will return numbers from 0 to 9 multiplied by 10.
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!
// This is a function with 2 parameters to concatenate 2 values
function s(w1, w2) {
return w1.concat(w2);
// The value of (w2) will be added to after the value of (w1);
return w1.concat(w2);
}

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 to expect in return
// 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 to expect in return
}

/* ======= TESTS - DO NOT MODIFY =====
Expand All @@ -20,25 +25,25 @@ To run these tests type `node 3-function-output` into your terminal
*/

function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED";
} else {
status = "FAILED";
}
let status;
if (expr) {
status = "PASSED";
} else {
status = "FAILED";
}

console.log(`${test_name}: ${status}`);
console.log(`${test_name}: ${status}`);
}

test(
"concatenate function - case 1 works",
concatenate("code", "your", "future") === "code your future"
"concatenate function - case 1 works",
concatenate("code", "your", "future") === "code your future"
);
test(
"concatenate function - case 2 works",
concatenate("I", "like", "pizza") === "I like pizza"
"concatenate function - case 2 works",
concatenate("I", "like", "pizza") === "I like pizza"
);
test(
"concatenate function - case 3 works",
concatenate("I", "am", 13) === "I am 13"
"concatenate function - case 3 works",
concatenate("I", "am", 13) === "I am 13"
);
Loading