-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
32 lines (29 loc) · 975 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var button = document.getElementById("submit");
button.onclick = performAction;
function performAction() {
let nValue = document.getElementById("nValue").value;
let range = document.getElementById("range").value;
let maxSum = document.getElementById("maxSum").value;
displayResult(nValue, range, maxSum);
}
function displayResult(nValue, range, maxSum) {
let status = false;
while(!status) {
let sum = 0;
let values = new Array(nValue);
for(i = 0; i < nValue; i++) {
values[i] = Math.round((Math.random() * range));
sum += values[i];
}
if(sum <= maxSum) {
status = true;
var result = document.getElementById("result");
let output = "Result: " + values[0];
for(i = 1; i < nValue; i++) {
output += ' + ' + values[i];
}
output += " = " + sum;
result.innerHTML = output;
}
}
}