-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavaScript on App Lab
66 lines (55 loc) · 1.98 KB
/
JavaScript on App Lab
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
// create a list of found mbps connection speeds
var callList = [8.2, 9.8, 6.2,];
var walkList = [15.3, 20.7, 17.1];
// Once the user is ready, click the button to begin the process and continue to various screens as they click additional buttons
onEvent("startButton", "click", function ( ) {
setScreen("locationOptionScreen");
});
onEvent("buttonDC", "click", function( ) {
setScreen("cityDC");
});
onEvent("buttonChickDC", "click", function( ) {
setScreen("loadingScreen");
timer();
connectionSpeed();
});
onEvent("restartButton", "click", function( ) {
setScreen("locationOptionScreen");
});
// count down to give the network connection time
function timer() {
// hide one of the images before timer starts
hideElement("wifiOne");
// create a variable to begin countdown
var timeLeft = 6;
// create a timed loop, counting in increments of 1 second
timedLoop(1000, function() {
// decrease the timeLeft by 1 second as a countdown
timeLeft = timeLeft - 1;
// track the timer in the console log and display it to the user
setText("setTextRelay", "Please wait for " + timeLeft + " seconds.");
console.log("Time Left: " + timeLeft);
// Switch between the images every second to create a blinker effect
if (timeLeft % 2 == 0){
hideElement("wifiTwo");
showElement("wifiOne");
} else {
hideElement("wifiOne");
showElement("wifiTwo");
}
// once the time is up, move to the screen for the loaded connection speeds
if (timeLeft == 0) {
stopTimedLoop();
setScreen("waitTimes");
}
});
}
// take from the list of mbps connection speeds and display them on the result screen
function connectionSpeed(){
// create variables to take a float from the list
var call = randomNumber(0, callList.length - 1);
var walk = randomNumber(0, walkList.length - 1);
// display the float to the label on the results page
setText("minutesCall", callList[call]);
setText("minutesWalk", walkList[walk]);
}