-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApple_Price_Compare.js
62 lines (49 loc) · 1.99 KB
/
Apple_Price_Compare.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
(function () {
"use strict";
window.onload = function(){
gallery();
userSignIn();
document.getElementById("submit").addEventListener("click", sub);
}
//Change the main image automatically
function gallery(){
let gallery = document.getElementById("imageGallery");
// Get the branch
let start = true;
let add = setInterval(function (){
if(start) {
let old = document.getElementById("mainPicture");
old.parentNode.removeChild(old);
//Randomly change the image
let random = parseInt(Math.random() * 10);
let img = document.createElement("img");
img.id = "mainPicture"
img.src = "img/" + random + ".jpeg";
gallery.append(img);
}else{
clearInterval(add)
}
},4000)
}
//Subscribe button action
function sub(){
alert("Thank you for subscription!")
}
//Create a personalized experience
function userSignIn() {
let name = prompt("Hi! What's your name?");
let random = parseInt(Math.random() * 100);
let user = document.getElementById("user");
if (name != null) {
if (random % 4 < 1) {
user.innerText = ("Hi " + name + "! Your lucky number is " + random + ". Do you want to buy a new Mac?");
} else if (random % 4 >= 1 && random % 4 < 2) {
user.innerText = ("Hi " + name + "! Your lucky number is " + random + ". Do you want to buy a new iPad?");
} else if (random % 4 >= 2 && random % 4 < 3) {
user.innerText = ("Hi " + name + "! Your lucky number is " + random + ". Do you want to buy a new iPhone?");
} else if (random % 4 >= 3 && random % 4 < 4) {
user.innerText = ("Hi " + name + "! Your lucky number is " + random + ". Do you want to buy a new Apple Watch?");
}
}
}
})();