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

Js week3 martin #90

Open
wants to merge 3 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
Binary file modified .DS_Store
Binary file not shown.
Binary file added week-1/.DS_Store
Binary file not shown.
Binary file added week-1/1-exercises/.DS_Store
Binary file not shown.
Binary file added week-1/2-mandatory/.DS_Store
Binary file not shown.
16 changes: 10 additions & 6 deletions week-1/2-mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

// 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 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) {
remainder = a % b;

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

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
9 changes: 5 additions & 4 deletions week-1/2-mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// 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;
var multipication = a * b * c;
return multipication;

}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
11 changes: 10 additions & 1 deletion week-1/2-mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
// Add comments to explain what this function does. You're meant to use Google!
// Returns a random number between 0 and 9 //
function getNumber() {
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!
// Combines two strings (w1 and w2) into one string //
function s(w1, w2) {
return w1.concat(w2);
}

function concatenate(firstWord, secondWord, thirdWord) {

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
var secondWord = " " + secondWord;
var thirdWord = " " + thirdWord;
var total = firstWord.concat(secondWord, thirdWord);
console.log(total);
return total;

}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
10 changes: 8 additions & 2 deletions week-1/2-mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
Sales tax is 20% of the price of the product
*/

function calculateSalesTax() {}
function calculateSalesTax(gross) {
return gross * 1.2
}

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

function formatCurrency() {}
function formatCurrency(x) {
var net = x * 1.2;
var result = net.toFixed([2]);
return "£" + result;
}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
Binary file added week-2/.DS_Store
Binary file not shown.
Binary file added week-2/1-exercises/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions week-2/1-exercises/B-boolean-literals/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/

var codeYourFutureIsGreat = true;
var mozafarIsCool = false;
var calculationCorrect = true;
var moreThan10Students = false;

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
6 changes: 3 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,14 @@

var studentCount = 16;
var mentorCount = 9;
var moreStudentsThanMentors; // finish this statement
var moreStudentsThanMentors = true; // finish this statement

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

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

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

// 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: 5 additions & 1 deletion week-2/1-exercises/E-conditionals/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

var name = "Daniel";
var danielsRole = "mentor";

if (danielsRole === "mentor") {
console.log("Hi, I'm Daniel, I'm a mentor")
} else if (danielsRole === "student") {
console.log("Hi, I'm Daniel, I'm a student")
}
/*
EXPECTED RESULT
---------------
Expand Down
21 changes: 19 additions & 2 deletions week-2/1-exercises/F-logical-operators/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,33 @@ 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;

if (htmlLevel > 5) {
var htmlLevelAbove5 = true;
} else {false
}
if (cssLevel > 5) {
var cssLevelAbove5 = true;
} else {var cssLevelAbove5 = false;}


// Finish the next two statement
// Use the previous variables and logical operators
// Do not "hardcode" the answers
var cssAndHtmlAbove5;
var cssOrHtmlAbove5;
if (htmlLevel > 5 && cssLevel > 5) {
cssAndHtmlAbove5 = true;
} else {cssAndHtmlAbove5 = false}

if (htmlLevel > 5 || cssLevel > 5) {
cssOrHtmlAbove5 = true;
} else {
cssOrHtmlAbove5 = false;
}

/*

DO NOT EDIT BELOW THIS LINE
--------------------------- */

Expand Down
17 changes: 16 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,8 +5,23 @@
Update the code so that you get the expected result.
*/

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

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

function isShortName (name) {
let stringLength = name.length;
return stringLength < 8;

}

function startsWithD (name) {
return name[0] === "D";
}
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
Expand Down
4 changes: 3 additions & 1 deletion week-2/1-exercises/G-conditionals-2/exercise-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

function negativeOrPositive(number) {

if (number < 0) {
return "negative";
} else {return "positive"}
}

/*
Expand Down
4 changes: 3 additions & 1 deletion week-2/1-exercises/G-conditionals-2/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
*/

function studentPassed(grade) {

if (grade < 50) {
return "failed";
} else {return "passed"}
}

/*
Expand Down
11 changes: 9 additions & 2 deletions week-2/1-exercises/G-conditionals-2/exercise-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
*/

function calculateGrade(mark) {

}
if (mark >= 80) {
return "A";
} else if (mark < 80 && mark > 60) {
return "B"
} else if (mark < 60 && mark >= 50){
return "C"
}
else {return "F"}
}

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
3 changes: 3 additions & 0 deletions week-2/1-exercises/G-conditionals-2/exercise-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*/

function containsCode(sentence) {
if (sentence.includes("code") === true) {
return true
} else {return false}

}

Expand Down
4 changes: 2 additions & 2 deletions week-2/1-exercises/H-array-literals/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Declare some variables assigned to arrays of values
*/

var numbers = []; // add numbers from 1 to 10 into this array
var mentors; // Create an array with the names of the mentors: Daniel, Irina and Rares
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; // add numbers from 1 to 10 into this array
var mentors = ["Daniel", "Irina", "Rares"]; // Create an array with the names of the mentors: Daniel, Irina and Rares

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
5 changes: 3 additions & 2 deletions week-2/1-exercises/I-array-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
*/

function isEmpty(arr) {
return; // complete this statement
if (arr.length > 0)
{return false;} // complete this statement
else {return true}
}

/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
Expand Down
4 changes: 2 additions & 2 deletions week-2/1-exercises/J-array-get-set/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/

function first(arr) {
return; // complete this statement
return arr[0]; // complete this statement
}

function last(arr) {
return; // complete this statement
return arr[arr.length - 1]; // complete this statement
}

/*
Expand Down
3 changes: 2 additions & 1 deletion week-2/1-exercises/J-array-get-set/exercises2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/

var numbers = [1, 2, 3]; // Don't change this array literal declaration

numbers.push(4);
numbers[0] = 1;
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
Expand Down
Loading