forked from verythorough/eye-chart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (27 loc) · 849 Bytes
/
script.js
File metadata and controls
31 lines (27 loc) · 849 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
var letterArray = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''),
numLetters = letterArray.length;
//Fisher-Yates shuffle
function shuffle (array) {
let i, j, temp;
for (i = array.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
function scrambleLetters () {
let letterDivs = document.querySelectorAll('.ltr'),
i = 0;
shuffle(letterArray);
for (i; i < numLetters; i++) {
letterDivs[i].textContent = letterArray[i];
}
}
scrambleLetters();
var scrambleBtn = document.createElement('button');
scrambleBtn.setAttribute('type', 'button');
scrambleBtn.name = 'scramble';
scrambleBtn.textContent = 'Scramble letters';
scrambleBtn.addEventListener('click', scrambleLetters);
document.getElementById('interface').appendChild(scrambleBtn);