-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (25 loc) · 842 Bytes
/
Copy pathscript.js
File metadata and controls
31 lines (25 loc) · 842 Bytes
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
"use strict";
const displayName = function(message) {
document.querySelector(".name").textContent = message;
};
let values = [];
function randomValue(val) {
let randomizer = Math.trunc(Math.random() * val.length);
for(let i = 0; i < val.length; i++) {
if(randomizer === i) {
displayName(`${val[i]}`);
}
};
};
document.addEventListener("keyup", function(e) {
if(e.keyCode === 32) {
randomValue(values);
}
});
//This adds more values to the end of values array
//You can add/delete these values in here
//Or you can write another values.push() with more values, that will be added to the current ones
values.push("Bob", "Jim", "Tom", "Anna", "Mark", "Peter", "Bill", "Donald");
document.querySelector(".again").addEventListener("click", function(e) {
randomValue(values);
});