-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
55 lines (43 loc) · 1.48 KB
/
app.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
alert("You can change the picture by clicking it!")
var button2= document.getElementById("bottomButton");
button2.addEventListener("click", bottomClick);
function changeBackgroundImg(){
var element = document.getElementById("backgroundPic");
if (element.style.backgroundImage.includes("https://tinyurl.com/3s5tcsrx")){
element.style.backgroundImage = "url('https://tinyurl.com/4nv635ze')";
} else {
element.style.backgroundImage = "url('https://tinyurl.com/3s5tcsrx')";
}
}
function populateImages(number){
const imageContainer= document.getElementById("imageContainer");
for (let index = 0; index < number; index++) {
const image = document.createElement("img");
image.src = "images/champpic2.jpg"
image.alt = "a picture of a dog"
imageContainer.appendChild(image)
}
}
function bottomClick(){
var userAnswer = prompt("How many do you want? 1-6")
var userNumber = parseInt(userAnswer)
if (!isNaN(userNumber) && userNumber >=1 && userNumber <=6){
console.log(userNumber)
populateImages(userNumber)
return userNumber;
} else {
alert("Please enter a valid number")
}
}
function askName(){
var name;
while(true){
name = prompt("Your name:");
if (name === null || name.trim() === "" ){
alert("Please enter a valid name.")
} else{
document.write("Welcome ", name);
break;
}
}
}