Skip to content

Commit 62ec41d

Browse files
committed
convert into loop
1 parent 3c75b9e commit 62ec41d

3 files changed

Lines changed: 15 additions & 16 deletions

File tree

chapter 14 to 16/script.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ document.write(`selected Cities List: </br> ${selected_cities} </br> </br>`);
148148
// Question# 12:
149149
// Write a program to create a single string from the
150150
// below mentioned array:
151+
151152
var arr = ["This", "is", " my", "cat"];
152153
// (Use array’s join method)
153154
var sentence = arr.join(" ");
@@ -158,19 +159,17 @@ document.write(`${sentence} </br></br>`);
158159
// Create a new array. Store values one by one in such a way
159160
// that you can access the values in the order in which they
160161
// were stored. (FIFO-First In First Out)
161-
162+
document.write(`FIFO-First In First Out</br>`);
162163
var elec_appliances = ["Fridge", "Fan", "Room Cooler", "Ac", "Iron", "Grinder"];
163-
document.write(`Out: </br> ${elec_appliances[0]}</br>`);
164-
document.write(`Out: </br> ${elec_appliances[1]}</br>`);
165-
document.write(`Out: </br> ${elec_appliances[2]}</br>`);
166-
document.write(`Out: </br> ${elec_appliances[3]}</br>`);
167-
document.write(`Out: </br> ${elec_appliances[4]}</br>`);
168-
document.write(`Out: </br> ${elec_appliances[5]}</br></br>`);
164+
for (i = 0; i < elec_appliances.length; i++) {
165+
document.write(`Out: </br> ${elec_appliances[i]}</br>`);
166+
}
169167

170168
// Question# 14:
171169
// Create a new array. Store values one by one in such a way
172170
// that you can access the values in reverse order. (Last In
173171
// First Out)
172+
document.write(`Last In First Out</br>`);
174173
var fabric = [
175174
"Lawn",
176175
"Silk",
@@ -179,12 +178,9 @@ var fabric = [
179178
"Pluster Cotton",
180179
"Georgette",
181180
];
182-
document.write(`Out: </br> ${fabric[5]}</br>`);
183-
document.write(`Out: </br> ${fabric[4]}</br>`);
184-
document.write(`Out: </br> ${fabric[3]}</br>`);
185-
document.write(`Out: </br> ${fabric[2]}</br>`);
186-
document.write(`Out: </br> ${fabric[1]}</br>`);
187-
document.write(`Out: </br> ${fabric[0]}</br></br>`);
181+
for (i = fabric.length - 1; i > 0; i--) {
182+
document.write(`Out: </br> ${fabric[i]}</br>`);
183+
}
188184

189185
// Question# 15:
190186
// Write a program to store phone manufacturers (Apple,
@@ -205,4 +201,4 @@ document.write(
205201
<option value="${ph_manufac[5]}">${ph_manufac[5]}</option>
206202
</select>
207203
</form>`
208-
);
204+
);

chapter 5/.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"liveServer.settings.port": 5501
3+
}

chapter 5/script.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ document.write(`${table} x 10 = ${table * 10} </br> </br></br>`);
109109

110110
document.write(`<h2>Celsius Temperature Calculation </h2>`);
111111

112-
var fahr_temp = 70;
112+
var fahr_temp = 88;
113113
var cels_calc = (fahr_temp - 32) * (5 / 9);
114114
document.write(
115115
`${fahr_temp}<sup>0</sup>F is ${cels_calc}<sup>0</sup>C </br></br>`
116116
);
117117

118118
document.write(`<h2>Fahrenheit Temperature Calculation </h2>`);
119119

120-
var cels_temp = 25;
120+
var cels_temp = 88;
121121
var fahr_calc = cels_temp * (9 / 5) + 32;
122122
document.write(`${cels_temp}<sup>0</sup>C is ${fahr_calc}<sup>0</sup>F </br>`);
123123

0 commit comments

Comments
 (0)