-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (36 loc) · 1.35 KB
/
Copy pathscript.js
File metadata and controls
40 lines (36 loc) · 1.35 KB
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
var init = new Date().getTime();
function getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
// this function will randomly choose any charector from the string
// that concatinate it which will show us a new number every time
return color;
}
function Move(){
// this will change the dimensions of box and position and color
var left;
var top;
var wh;
left= Math.random()*500;
top = Math.random()*250;
wh= (Math.random()*400) + 100;
document.getElementById("Box").style.left= left +"px"; //change the item to pixels
document.getElementById("Box").style.top = top +"px";
document.getElementById("Box").style.width = wh +"px";
document.getElementById("Box").style.height = wh + "px";
document.getElementById("Box").style.display = "block";
document.getElementById("Box").style.backgroundColor = getRandomColor(); // change the color
init = new Date().getTime();
}
Move();
document.getElementById("Box").onclick= function(){
document.getElementById("Box").style.display="none";
var now = new Date().getTime();
var diff = now - init; // diff is time differece between previously called init time
diff= diff/1000;
alert("You took "+ diff +" sec");
Move();
}