From 616eee59cae964656ad92dd0445fe2c94272c3c3 Mon Sep 17 00:00:00 2001 From: OCC Date: Sat, 29 Nov 2025 12:38:05 +0100 Subject: [PATCH] Initial commit --- js1-wk1-eval/level-100.js | 5 ++++- js1-wk1-eval/level-200.js | 9 +++++---- js1-wk1-eval/level-300.js | 6 ++++-- js1-wk1-eval/level-400.js | 10 +++++++--- js1-wk1-eval/level-500.js | 7 +++++-- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/js1-wk1-eval/level-100.js b/js1-wk1-eval/level-100.js index 15d627bb..979fc28e 100644 --- a/js1-wk1-eval/level-100.js +++ b/js1-wk1-eval/level-100.js @@ -6,4 +6,7 @@ // b) 59 divided by 7 ( to 4 decimal places ) // c) 67 plus 100 -// Write your answers below: \ No newline at end of file +// Write your answers below: +// a) 560 +// b) 8.4285 +// c) 167 \ No newline at end of file diff --git a/js1-wk1-eval/level-200.js b/js1-wk1-eval/level-200.js index c1887876..816ead73 100644 --- a/js1-wk1-eval/level-200.js +++ b/js1-wk1-eval/level-200.js @@ -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. diff --git a/js1-wk1-eval/level-300.js b/js1-wk1-eval/level-300.js index da4ee3ca..4b9f46d3 100644 --- a/js1-wk1-eval/level-300.js +++ b/js1-wk1-eval/level-300.js @@ -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 \ No newline at end of file diff --git a/js1-wk1-eval/level-400.js b/js1-wk1-eval/level-400.js index c3372a78..e9d31b5c 100644 --- a/js1-wk1-eval/level-400.js +++ b/js1-wk1-eval/level-400.js @@ -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? \ No newline at end of file +//1 input to repeat — how many times to repeat "x" +// e) What kind of statement is on line 7? +//It’s an assignment statement \ No newline at end of file diff --git a/js1-wk1-eval/level-500.js b/js1-wk1-eval/level-500.js index 74846ea9..7b738fd1 100644 --- a/js1-wk1-eval/level-500.js +++ b/js1-wk1-eval/level-500.js @@ -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 \ No newline at end of file +// 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.