-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodeSample.js
65 lines (49 loc) · 2.03 KB
/
CodeSample.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* basic fizzBuzz on a website, with parameters for later substitution*/
var fizzBuzzDiv = document.getElementsByClassName("fizzBuzz");
var theBuzz = function(a, b) {
fizzBuzzDiv[0].innerHTML = ""
for(i=1; i<101; i++){
if(i%15===0){
var nextNumber = document.createElement("p");
nextNumber.innerHTML = a + b + "!";
fizzBuzzDiv[0].appendChild(nextNumber);
}
else if(i%3===0){
var nextNumber = document.createElement("p");
nextNumber.innerHTML = a;
fizzBuzzDiv[0].appendChild(nextNumber); }
else if(i%5===0){
var nextNumber = document.createElement("p");
nextNumber.innerHTML = b;
fizzBuzzDiv[0].appendChild(nextNumber); }
else {
var nextNumber = document.createElement("p");
nextNumber.innerHTML = i;
fizzBuzzDiv[0].appendChild(nextNumber); }
}
}
/* routing so the Got It button redirects to the Play page when clicked*/
var gotItButton = document.getElementById("noPageButton");
var redirectToPlay = function() {
window.location.href='play.html';
}
/* functionality to change the words "fizz" and "buzz"*/
var playButton = document.getElementById("playNow");
var homeLink = document.getElementsByTagName("a")
var playFizzBuzz = function(event) {
homeLink[0].style.display = "none";
var newFizz = document.getElementById("newFizz").value;
var newBuzz = document.getElementById("newBuzz").value;
var homeLinkAfter = document.getElementById("homeLink");
theBuzz(newFizz, newBuzz);
homeLinkAfter.appendChild(homeLink[0]);
homeLink[0].style.display = "inline"
}
playButton.addEventListener("click", playFizzBuzz);
/* Greet my user on the play page */
var greetingHtml = document.querySelector("h1")
if (person != null && person != "") {
var greeting = document.createElement("h1");
greeting.innerHTML = "Ok, " + person + ".<br/> Would you like to make FizzBuzz your own?";
greetingHtml.appendChild(greeting)
}