-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp01.js
More file actions
83 lines (73 loc) · 3.14 KB
/
app01.js
File metadata and controls
83 lines (73 loc) · 3.14 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
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
72
73
74
75
76
77
78
79
80
81
82
83
// Function 1: displays image of pepper type selected in radio button, if no button is selected, will "no pepper type selected"
function spicy(input)
{
if(input == 'mild')
{
document.getElementById("pepperimg").innerHTML='<img src="red_bell_pepper.jpeg">';
} else if(input == "medium")
{
document.getElementById("pepperimg").innerHTML='<img src="red_jalapeno.jpeg">';
} else if(input == "hot")
{
document.getElementById("pepperimg").innerHTML='<img src="red_carolina_reaper.jpeg">';
} else
{
document.getElementById("pepperimg").innerHTML='';
}
}
// Function 2: Prompts user if they live in seattle or not, and returns hariness zone if they do.
// attempting to add input detection loop
// let usrResponse = "Type Y or N";
// function seattleLocal()
// {
// let local = prompt("Do you live in Seattle?", usrResponse);
// console.log(local)
// if(local == "Y" || local == "y"){
// document.write('<h2> Hardiness Zone for Seattle is 8b, planting for peppers is ideal in late May</h2>')
// } else if (local.toUpperCase() == "N"){ //.toUpperCase() forces input from user to be compaired as uppercase
// document.write('<h2> Sorry no information for your region </h2>')
// } else {
// usrResponse = "Wrong Input!!! Type Y or N";
// seattleLocal();
// }
// }
//Function 2: Should perform the same as a Function 2 commented out above, but this time it is executed with a while loop.
function seattleLocal()
{
let local = prompt("Do you live in Seattle?", "Type Y or N");
console.log(local)
while(local.toUpperCase() != "Y" && local.toUpperCase() != "N"){
local = prompt("Do you live in Seattle?", "Wrong Input!!! Type Y or N");
console.log(local);
}
if(local == "Y" || local == "y"){
document.write('<h2> Hardiness Zone for Seattle is 8b, planting for peppers is ideal in late May</h2>')
} else if (local.toUpperCase() == "N"){ //.toUpperCase() forces input from user to be compaired as uppercase
document.write('<h2> Sorry no information for your region </h2>')
}
}
//Function 3: Places the current date on the website.
function yourDate()
{
let currentDate = new Date();
console.log(currentDate);
let day = currentDate.getDate();
console.log(day);
let month = currentDate.getMonth() + 1; //(january is 0 so add 1)
console.log(month);
let year = currentDate.getFullYear();
console.log(year);
document.write('Today is: ' + month + '/' + day + '/' + year);
}
//Function 4: Checks number entered by user and then runs a loop to store the img url in pepperImg until the condition is met, then writes the string to the inner HTML to make that same number of peppers populate.
function cartAdd()
{
let qty = document.getElementById("pepperCart").value; //.value pulls the number value from the number box field
console.log(qty);
let pepperImg = ''
for (let i=0; i<qty; i++){
pepperImg = pepperImg + '<img id="emoji" src="red_pepper_emoji.png">';
//console.log(pepperImg);
}
document.getElementById("showCart").innerHTML=pepperImg;
}