Skip to content

Commit

Permalink
W01
Browse files Browse the repository at this point in the history
  • Loading branch information
uthbees committed Feb 28, 2024
1 parent 564eecc commit ac2a85a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
20 changes: 20 additions & 0 deletions w01-task.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>W01: Programming Task</title>
</head>

<body>
<h1>W01: Programming Task</h1>
<h2>Ethan Ball</h2>
<p>All the work will be displayed in the console window of the browser.
<br>To view the console in the browser, use Inspect -> Console Panel.
</p>

<script src="w01-task.js"></script>

</body>
</html>
25 changes: 25 additions & 0 deletions w01-task.js
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit ac2a85a

Please sign in to comment.