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

Javascript/week3/nihal #85

Open
wants to merge 22 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
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\week-1\\2-mandatory\\3-function-output.js"
}
]
}
1 change: 1 addition & 0 deletions week-1/1-exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
var name = "Hello world!";
console.log("Hello world");
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`

var greeting ="Hello World";
console.log(greeting);
console.log(greeting);
console.log(greeting);
4 changes: 3 additions & 1 deletion week-1/1-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";
var messageType = typeof message;

console.log(message);
console.log(messageType);
7 changes: 6 additions & 1 deletion week-1/1-exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Start by creating a variable `message`
var greetingStart = "Hello, my name is ";
var name = "Nihal";

var greeting = greetingStart + name;

console.log(greeting);

console.log(message);
5 changes: 4 additions & 1 deletion 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`
var name = "Daniel";
var nameLength = name.length;

console.log(nameLength);

console.log(message);
5 changes: 3 additions & 2 deletions week-1/1-exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const name = " Daniel ";
var name = "Daniel";
var nameLowerCase = name.toLowerCase();

console.log(message);
console.log(nameLowerCase);
3 changes: 3 additions & 0 deletions week-1/1-exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
var numberOfStudent = 15;
var numberOfMentors = 8;
var sum = numberOfStudent + numberOfMentors;
4 changes: 3 additions & 1 deletion week-1/1-exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
var numberOfStudents = 8;
var total = numberOfStudents + numberOfStudents;
var percentagOfStudents = Math.round((numberOfStudents/total)*100);
4 changes: 2 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,6 @@
// Complete the function so that it takes input parameters
function multiply() {
// Calculate the result of the function and return it
function multiply(a, b) {
return a*b;
}

// 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,4 +1,6 @@
// Declare your function first
function divide(a, b) {
return a/b;
}

var result = divide(3, 4);

Expand Down
6 changes: 4 additions & 2 deletions 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(num1, num2) {
return num1 + num2;
}

var greeting = createGreeting("Daniel");
var greeting = createGreeting("Hello, my name is ", "Nihal.");

console.log(greeting);
6 changes: 3 additions & 3 deletions week-1/2-mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

// 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 getAddition(a, b) {
total = a ++ b
total = a + b

// Use string interpolation here
return "The total is %{total}"
Expand Down
28 changes: 18 additions & 10 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 @@ -22,14 +21,23 @@ To run these tests type `node 2-logic-error` into your terminal
function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED"
status = 'PASSED';
} else {
status = "FAILED"
status = 'FAILED';
}

console.log(`${test_name}: ${status}`)
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
);
16 changes: 11 additions & 5 deletions week-1/2-mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
// Add comments to explain what this function does. You're meant to use Google!

//returen random number between 0 ans 9.99
function getNumber() {
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!

// this function takes one array and merges into another
// if first parameter w1 is a string, then it will do just a string concatenation
function s(w1, w2) {
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
return `${firstWord} ${secondWord} ${thirdWord}`;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand All @@ -22,23 +28,23 @@ To run these tests type `node 3-function-output` into your terminal
function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED";
status = 'PASSED';
} else {
status = "FAILED";
status = 'FAILED';
}

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

test(
"concatenate function - case 1 works",
concatenate("code", "your", "future") === "code your future"
concatenate('code', 'your', 'future') === 'code your future'
);
test(
"concatenate function - case 2 works",
concatenate("I", "like", "pizza") === "I like pizza"
concatenate('I', 'like', 'pizza') === 'I like pizza'
);
test(
"concatenate function - case 3 works",
concatenate("I", "am", 13) === "I am 13"
concatenate('I', 'am', 13) === 'I am 13'
);
13 changes: 9 additions & 4 deletions week-1/2-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(price) {
const tax = price * 0.2;
const totalPrice = tax + price;
return totalPrice;

/*
CURRENCY FORMATTING
Expand All @@ -28,9 +31,9 @@ To run these tests type `node 4-tax.js` into your terminal
function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED";
status = 'PASSED';
} else {
status = "FAILED";
status = 'FAILED';
}

console.log(`${test_name}: ${status}`);
Expand All @@ -51,4 +54,6 @@ test(
"formatCurrency function - case 2 works",
formatCurrency(17.5) === "£21.00"
);
test("formatCurrency function - case 3 works", formatCurrency(34) === "£40.80");
test(
"formatCurrency function - case 3 works", formatCurrency(34)
=== "£40.80");
12 changes: 7 additions & 5 deletions week-2/1-exercises/B-boolean-literals/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
Add the required variables with the correct boolean values assigned.
*/

var codeYourFutureIsGreat = true;

/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
let codeYourFutureIsGreat = true;
let mozafarIsCool = false;
let calculationCorrect = true;
let moreThan10Students = false;

/* DO NOT EDIT BELOW THIS LINE
---------------------------
*/
console.log("Is Code Your Future great?", codeYourFutureIsGreat);
console.log("Is Mozafar cool?", mozafarIsCool);
console.log("Does 1 + 1 = 2?", calculationCorrect);
Expand Down
7 changes: 4 additions & 3 deletions week-2/1-exercises/C-comparison-operators/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

var studentCount = 16;
var mentorCount = 9;
var moreStudentsThanMentors; // finish this statement
var sum = studentCount + mentorCount;
var moreStudentsThanMentors = studentCount > mentorCount; // finish this statement

var roomMaxCapacity = 25;
var enoughSpaceInRoom; // finish this statement
var enoughSpaceInRoom = roomMaxCapacity === sum; // finish this statement

var personA = "Daniel";
var personB = "Irina";
var sameName; // finish this statement
var sameName = personA === personB; // finish this statement

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
3 changes: 2 additions & 1 deletion week-2/1-exercises/D-predicates/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

// Finish the predicate function to test if the passed number is negative (less than zero)
function isNegative(number) {
return number > 0;

}

// Finish the predicate function to test if the passed number is between 0 and 10
function isBetweenZeroAnd10(number) {

return number > 0 && number < 10;
}

/*
Expand Down
6 changes: 6 additions & 0 deletions week-2/1-exercises/E-conditionals/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

var name = "Daniel";
var danielsRole = "mentor";
if (danielsRole === `mentor`) {
console.log("Hi, I'm Daniel, I'm a mentor.");
}
else {
console.log("Hi, I'm Daniel, I'm a student.");
}

/*
EXPECTED RESULT
Expand Down
8 changes: 4 additions & 4 deletions week-2/1-exercises/F-logical-operators/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ var cssLevel = 4;

// Finish the statement to check whether HTML, CSS knowledge are above 5
// (hint: use the comparison operator from before)
var htmlLevelAbove5;
var cssLevelAbove5;
var htmlLevelAbove5 = htmlLevel > 5;
var cssLevelAbove5 = cssLevel > 5;

// Finish the next two statement
// Use the previous variables and logical operators
// Do not "hardcode" the answers
var cssAndHtmlAbove5;
var cssOrHtmlAbove5;
var cssAndHtmlAbove5 = htmlLevelAbove5 && cssLevelAbove5;
var cssOrHtmlAbove5 = htmlLevelAbove5 || cssLevelAbove5;

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
24 changes: 23 additions & 1 deletion week-2/1-exercises/F-logical-operators/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,29 @@
Update the code so that you get the expected result.
*/

function isNegative() {}
function isNegative(number) {
return number < 0;
}


function isNegative(number) {
return number < 0;
}


function isBetween5and10(number) {
return number >= 5 && number <= 10;
}


function isShortName(name) {
return name.length >= 6 && name.length <= 10;
}


function startsWithD(name) {
return name[0] === "D";
}

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
Loading