For this activity, you may work alone or with another student in this class. Write JavaScript code to solve the following problems.
To run your program, you may:You may simply allow the script to be executed as the HTML page is loaded. Open the browser's console to see the result.
Alternatively, you may write HTML code to call the JavaScript function; you may need to modify your JavaScript such that the results are written as part of the HTML document.
Use simplegrid.js,
complete at least one of the functions:
isDiagonal
, isEdge
, or isMiddleRow
.
isDiagonal
function to
return either "diagonal" or "not diagonal" depending on
whether or not the tile is along the diagonal of the square grid.
For example, on a 7x7 grid,
assuming the tile numbers (starting at the top-left corner)
are 1, 2, 3, ..., 491 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | ||||||
15 | ||||||
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | |||||
36 | ||||||
43 |
all yellow tiles are on the diagonal.
You may use the following formulas in your program as needed:
var row = Math.floor((tile-1)/width); // Math.floor returns the largest integer less than or equal to a given number var col = (tile-1) % width; // % returns the remainder of the division
isEdge
function to
return either "edge" or "not edge" depending on
whether or not the tile is along the edge of grid.
For example, on a 7x8 grid,
assuming the tile numbers (starting at the top-left corner)
are 1, 2, 3, ..., 561 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | ||||||
15 | ||||||
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | |||||
36 | ||||||
43 | ||||||
50 |
all yellow tiles are on the edge.
You may use the following formulas in your program as needed:
var row = Math.floor((tile-1)/width); // Math.floor returns the largest integer less than or equal to a given number var col = (tile-1) % width; // % returns the remainder of the division
isMiddleRow
function to
return either "middle row" or "no" depending on
whether or not the tile is along the middle row(s) of the grid.
For example, on a 7x8 grid,
assuming the tile numbers (starting at the top-left corner)
are 1, 2, 3, ..., 561 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | ||||||
15 | ||||||
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | |||||
36 | ||||||
43 | ||||||
50 |
all yellow tiles are on the edge.
You may use the following formulas in your program as needed:
var row = Math.floor((tile-1)/width); // Math.floor returns the largest integer less than or equal to a given number var col = (tile-1) % width; // % returns the remainder of the division
Use array-loop.js,
complete at least one of the functions: sumList
,
findLast
, or sum2D
.
sumList
function that takes a non-empty list of integers,
and then returns the sum of all elements in the list.
findLast
function that takes a non-empty list of integers,
and then returns the position of the last occurrence of the largest element.
sum2D
function that takes a non-empty, square, two-dimentional array of integers,
and then returns the sum of all the elements in the array.
Submit your POTD to Collab (under Assignment/POTD2). Please include all team member names.
If you have multiple files, do not zip them. Each team submits only one copy.