-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |