Skip to content
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
5 changes: 4 additions & 1 deletion js1-wk1-eval/level-100.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
// b) 59 divided by 7 ( to 4 decimal places )
// c) 67 plus 100

// Write your answers below:
// Write your answers below:
// a) 560
// b) 8.4285
// c) 167
9 changes: 5 additions & 4 deletions js1-wk1-eval/level-200.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
// Write your answers down below:

// a) 10.53 For example, Math.trunc(10.53) evaluates to 10, Math.floor(10.53) evaluates to 10
// b) 170.105
// c) -0.34
// d) -8.921
// b) 170.105 Math.trunc(170.105) evaluates to 170, Math.floor(170.105) evaluates to 170
// c) -0.34 Math.trunc(-0.34) evaluates to 0, Math.floor(-0.34) evaluates to -1
// d) -8.921 Math.trunc(-8.921) evaluates to -8, Math.floor(-8.921) evaluates to -9

// Part 2: Use the Node REPL to check your answers to Part 1)
// Part 3: Using Part 2, explain the difference between Math.trunc() and Math.floor() in your own words

// Math.trunc() cuts off everything after the decimal — it just removes the fractional part.
// Math.floor() always rounds down to the nearest whole number — even if the number is negative.



6 changes: 4 additions & 2 deletions js1-wk1-eval/level-300.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ const time = "21:49";
const macTimeDisplay = `${day.slice(0,3)} ${date} ${month.slice(0,3)} ${time}`;

// Before running code, answer the following - write down your answers:
// a) how many function calls are there in this file?
// b) predict and explain what macTimeDisplay will evaluate to. You can use documentation to look up slice
// a) how many function calls are there in this file? (2)
// b) predict and explain what macTimeDisplay will evaluate to. You can use documentation to look up slice
// a) 2
// b) Fri 29 Sep 21:49
10 changes: 7 additions & 3 deletions js1-wk1-eval/level-400.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ const secret = "cake";
confession = confession.replaceAll(secret,'x'.repeat(secret.length));


// a) How many function calls are there in this file?
// a) How many function calls are there in this file? 2
// b) Explain what the expression confession.replaceAll(secret,'x'.repeat(secret.length)); is doing
// c) How many inputs do we pass to replaceAll when we call it? How can you tell?
//It finds every "cake" in the text and replaces each one with "xxxx".
// c) How many inputs do we pass to replaceAll when we call it? How can you tell?
// 2 inputs to replaceAll — the word to find and the word to replace it with.
// d) How any inputs do we pass to repeat when we call it? How can you tell?
// e) What kind of statement is on line 7?
//1 input to repeat — how many times to repeat "x"
// e) What kind of statement is on line 7?
//It’s an assignment statement
7 changes: 5 additions & 2 deletions js1-wk1-eval/level-500.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
const avgDaysInMonth = Math.floor(365 / 12);

// Without running any code,
// Predict and explain what the value of avgDaysInMonth will evaluate to
// You can use documentation to look up what Math.floor does
// Predict and explain what the value of avgDaysInMonth will evaluate to 30
// You can use documentation to look up what Math.floor does
//Answer Because:
//365 / 12 ≈ 30.4166 and Math.floor takes this number and cuts off everything after the decimal, rounding down.
//So it simply becomes 30.