-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript practice.js
More file actions
192 lines (147 loc) · 4.51 KB
/
javascript practice.js
File metadata and controls
192 lines (147 loc) · 4.51 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// Currency Conversion
// var convertToNaira = Exchange Rate
// EXCHANGE RATE = 550Naira to 1 Dollar
var rate = 620;
document.getElementById("rate").innerHTML = (rate);
function dollarToNaira(){
const currency1 = document.getElementById("currency1").value;
var dollar = (rate * currency1);
document.getElementById("yourTotalAmount").innerHTML = ("You have " + dollar + " Naira");
}
// for converting Naira To Dollar = (Naira * Excange rate);
/*function dollarToNaira (){
var toDollar = prompt ("How much Dollar do you want to convert?");
var dollar = (rate * toDollar);
}*/
// for converting Dollar To Naira = (Naira / Excahnge rate);
function nairaToDollar (){
const currency1 = document.getElementById("currency1").value;
var naira = (currency1 / rate);
document.getElementById("yourTotalAmount").innerHTML = ("You have " + naira.toFixed(2) + " Dollar");
};
// to reset the currency
function reset(){
document.getElementById("currency1").inputMode.style.display = "none";
};
// project two
let buttons = Array.from(document.getElementsByClassName('btn'));
let project2 = document.getElementById("project_2");
buttons.map( btn => {
btn.addEventListener('click', (e) => {
project2.style.backgroundColor = ((btn).value);
document.getElementById("color").innerHTML =
("you have change the background color to " + (btn).value)
});
});
function resetBgcolor(){
project2.style.backgroundColor = "white"
};
// project three
// Days in a month
// choosing a date with more than one switch case
var days = "";
function getbirthmonth(){
var month = document.getElementById ("birthMonth").value;
switch(+month) {
case 1:
case 2: days = 28;
break;
case 3:
case 4: days = 30;
break;
case 5:
case 6: days = 30;
break;
case 7:
case 8:
case 9: days = 30;
break;
case 10:
case 11: days = 30;
break;
case 12: days = 31;
break;
};
document.getElementById ("yourBirthMonthIs").innerHTML = ("There are " + days + " days in this month.");
};
// Educationa and Salary earned
var salary = "";
var education = document.getElementById("eduQualification").value;
function showSalary(){
switch (education) {
case "noHighSchool":
salary = 25636;
break;
case "highSchool":
salary = 35256;
break;
case "Associate":
salary = 41496;
break;
case "Bachelor":
salary = 59124;
break;
case "Master":
salary = 69732;
break;
case "Professional":
salary = 89960;
break;
case "Doctoral":
salary = 52325520;
break;
};
document.getElementById("salary").innerHTML = ("In 2015, a person with "+education+" earned an average of #"+salary.toLocaleString("en-US")+"/year.");
};
// project four
var operators = Array.from(document.getElementsByClassName("operator"));
operators.map( operator => { operator.addEventListener('click', (e) =>{
operate = (e.target.value)
// return (operator.value)
});
});
function calculate(){
var n1 = parseFloat(document.getElementById('n1').value);
var n2 = parseFloat(document.getElementById('n2').value);
if (operate === '+')
{
document.getElementById('answer').value = n1+n2;
}
if (operate === '-')
{
document.getElementById('answer').value = n1-n2;
}
if (operate === '*')
{
document.getElementById('answer').value = n1*n2;
}
if (operate === '/')
{
document.getElementById('answer').value = n1/n2;
}
};
// project Five
// winner and prize
let prize = "";
function getSelectedValue()
{
var winner = document.getElementById("list").value;
switch (winner) {
case 1:
prize += "a trip for two to the Bahamas and ";
case 2:
prize += "a four piece furniture set.";
break;
case 3:
prize += "a smartwatch and ";
default:
prize += "tickets to the circus.";
}
document.getElementById("myPrize").innerHTML = ("You've won " + prize);
}
// Project Six
var myOdds = 40;
function generateNumber(){
document.getElementById("RandomNumber").innerHTML =
Math.floor(Math.random() * myOdds );
};