diff --git a/w01-task.html b/w01-task.html new file mode 100644 index 0000000..6d424eb --- /dev/null +++ b/w01-task.html @@ -0,0 +1,20 @@ + + + + + + + W01: Programming Task + + + +

W01: Programming Task

+

Ethan Ball

+

All the work will be displayed in the console window of the browser. +
To view the console in the browser, use Inspect -> Console Panel. +

+ + + + + diff --git a/w01-task.js b/w01-task.js new file mode 100644 index 0000000..b07c893 --- /dev/null +++ b/w01-task.js @@ -0,0 +1,25 @@ +// 🔍 Part 1 error +let userName = "Moroni"; +console.log(`Username: ${userName}`); +userName = "Moronihah"; +console.log(`Username: ${userName}`); + +// 🔍 Part 2 error +const currentDateAndTime = new Date().toString(); +console.log(`It is now ${currentDateAndTime}`); + +// 🔍 Part 3 error. The following statement calls a function named total that accepts any number of arguments and returns the sum. The returned value is stored in a variable named theTotal. 1-10 are the arguments. + +let theTotal = total(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); +console.log(`The total is ${theTotal}`); + +// 'total' function declaration +function total(...theNumbers) { + let sum = 0; + theNumbers.forEach((number) => { + // sum += aNumber * 1; // Why do we use * 1? It implicitly converts a string to a number. + // You should never actually do that though, since it's terrible for readability. + sum += parseInt(number) + }) + return sum +}