init
This commit is contained in:
30
html/tasks/chapter_5/task11_tables/oppgave.html
Normal file
30
html/tasks/chapter_5/task11_tables/oppgave.html
Normal file
@@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Oppgave 11</title>
|
||||
<link rel="stylesheet" href="../../../../resources/css/main.css">
|
||||
<script async src="./script.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Oppgave 11</h1>
|
||||
|
||||
<div class=center>
|
||||
<div class="inline">
|
||||
Lag <input type="number" id="amount" value="0" min="0" max="999"> tilfeldige tall mellom 0 og <input type="number" id="range" value="0" min="0">
|
||||
<button id="reload">Reload</button>
|
||||
</div>
|
||||
|
||||
<table id="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tall</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
34
html/tasks/chapter_5/task11_tables/script.js
Normal file
34
html/tasks/chapter_5/task11_tables/script.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const table = document.getElementById("table");
|
||||
const globalAmount = document.getElementById("amount");
|
||||
const globalRange = document.getElementById("range");
|
||||
const reloadButton = document.getElementById("reload");
|
||||
|
||||
const listHeader = table.innerHTML;
|
||||
|
||||
globalAmount.addEventListener("input", updateList, false);
|
||||
globalRange.addEventListener("input", updateList, false);
|
||||
reloadButton.addEventListener("click", updateList, false);
|
||||
|
||||
function updateList() {
|
||||
addToList(generateNums(globalAmount.value, globalRange.value), table);
|
||||
}
|
||||
|
||||
function addToList(numArray, table) {
|
||||
rows = '';
|
||||
for (i in numArray) {
|
||||
rows += '<tr><td>' + numArray[i] + '</td></tr>';
|
||||
}
|
||||
table.innerHTML = listHeader + rows;
|
||||
}
|
||||
|
||||
function generateNums(amount, range) {
|
||||
let array = [];
|
||||
for (i=0; i<amount; i++) {
|
||||
array[i] = Math.ceil(Math.random()*range);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
function sumTable(table) {
|
||||
|
||||
}
|
Reference in New Issue
Block a user