-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript.js
71 lines (55 loc) · 1.55 KB
/
javascript.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
60
61
62
63
64
65
66
67
68
69
70
71
var body
var maindiv
function ready(){
body = document.querySelector("body")
createmaindiv()
createpromptbutton()
}
function createmaindiv(){
let newdiv = document.createElement("div")
maindiv = newdiv
maindiv.id = "maindiv"
body.appendChild(maindiv)
}
function gridhoverlistener(div){
div.addEventListener("mouseover", hovereddiv)
div.addEventListener("mouseout", unhovereddiv)
}
function hovereddiv(){
event.target.style.backgroundColor = "red"
}
function unhovereddiv(){
event.target.style.backgroundColor = "gray"
}
function creategrid(amount){
let size = 800 / amount
let sizestring = size + "px"
for (let i = 0; i<amount;i++){
let newrow = document.createElement("div")
newrow.className = "row"
for (let i = 0; i<amount; i++){
let newdiv = document.createElement("div")
gridhoverlistener(newdiv)
newdiv.style.width = sizestring
newdiv.style.height = sizestring
newdiv.className = "singlediv"
newrow.appendChild(newdiv)
}
maindiv.appendChild(newrow)
}
}
function createpromptbutton(){
let promptbutton = document.createElement("button")
promptbutton.addEventListener("click", giveprompt)
promptbutton.style.alignSelf = "center"
body.appendChild(promptbutton)
}
function giveprompt(){
let amount = prompt("How many squares?")
if (amount.typeof = "number"){
if (amount <= 100){
creategrid(amount)
event.target.remove()
}
}
}