-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
320 lines (215 loc) · 7.04 KB
/
script.js
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
'use strict'
const marksMass = 78
const marksHeight = 1.69
let johnsMass = 92
let johnsHeight = 1.95
function calculateBMI(mass, height){
const bmi = mass/(height**2)
return bmi;
}
const marksBMI = calculateBMI(marksMass, marksHeight);
console.log('Marks BMI '+marksBMI)
const johnsBMI = calculateBMI(johnsMass, johnsHeight);
console.log('Johns BMI '+johnsBMI)
function markHigherBMI(bmi1, bmi2){
return bmi1 > bmi2
}
const bmiFlag = markHigherBMI(marksBMI, johnsBMI)
console.log(bmiFlag)
const marksObject = {
fullName: 'Mark Miller',
mass: 78,
height: 1.69
}
const johnsObject = {
fullName: 'John Smith',
mass: 92,
height: 1.95
}
const calBMI = () => {
const bmi = johnsObject.mass/((johnsObject.height)**2)
console.log('=========BMI========== ', bmi)
return bmi
}
console.log(calBMI());
const age = 19
const isOldEnough = age >= 19
if(!isOldEnough){
console.log("Eligible for vote")
}
else {
console.log("Not eligible to vote")
}
const num = Number('999')
console.log(num+1)
console.log('100'+1)
console.log('100'-1)
if('praveen') console.log('praveen')
if(NaN) console.log('Not a number')
console.log(typeof Number('1000'))
console.log(typeof String(1000))
console.log('1' == 1);
console.log('1' === 1);
console.log('===============================')
const hasDriversLicense = true
const hasGoodVision = false
console.log(hasDriversLicense && hasGoodVision)
console.log(hasDriversLicense || hasGoodVision)
console.log(!hasDriversLicense && hasGoodVision)
console.log(hasDriversLicense || !hasGoodVision)
// coding challenge3
const dolphinsAvgScore = (97+112+101)/3
const koalasAvgScore = (109+95+107)/3
const minimumScore = 100
console.log('Average score of Dolphins team '+dolphinsAvgScore, 'Average score of Koalas team '+koalasAvgScore)
if((dolphinsAvgScore > koalasAvgScore) && (dolphinsAvgScore >= minimumScore)) console.log('Dolphins team won ')
else if((dolphinsAvgScore < koalasAvgScore) && (koalasAvgScore >= minimumScore)) console.log('Koalas team won')
else if(dolphinsAvgScore === koalasAvgScore) console.log('Match drwan between Dolphins team and Koalas team')
else console.log('No team has won! ')
const day = 'Thursday'
switch(day) {
case 'Monday':
console.log('Dizzy day')
break
case 'Tueseday':
console.log('On track day')
break
case 'Thursday':
default:
console.log('Holiday')
}
const isMember = false
let checkMemberShip = isMember ? 'Free of cost' : 'Need to some amount'
console.log(checkMemberShip)
const adultAge = 18
const beverage = adultAge >=20 ? 'Beer' : 'Juice'
console.log(beverage)
const billValue = 430
const tipTobePaid = (billValue >= 15 && billValue <= 300) ? 15 : 20
const tipValue = billValue*(tipTobePaid/100)
console.log(billValue+tipValue)
const bills = [125, 555, 44]
const finalTip = function(bill){
return (bill >= 15 && bill <= 300) ? bill*0.15 : bill*0.2
}
const tips = [finalTip(bills[0]), finalTip(bills[1]), finalTip(bills[2])]
const totalBillWithTips = [bills[0]+tips[0], bills[1]+tips[1], bills[2]+tips[2]]
console.log('totalBillWithTips '+totalBillWithTips);
function calcRectArea(width, height){
return width*height;
}
const recArea = calcRectArea(10, 12)
console.log('Rectangle area '+recArea)
const getRectArea = function(width, height){
return width*height;
}
console.log('Get rectangle area '+getRectArea(4, 12))
const getAge = (birthYear) => {
return 2030 - birthYear
}
console.log('Get age '+getAge(1998))
const greet = (name) => {
console.log(name)
return 'Hi '+name+' Good Morning!'
}
console.log(greet('praveen'));
const yearsUntilRetirement = (birthYear, firstName) => {
const calCurrentAge = 2030-birthYear
const retireAge = 65 - calCurrentAge
return `${firstName} retires in ${retireAge} years`
}
console.log(yearsUntilRetirement(1991, 'praveen'));
console.log(yearsUntilRetirement(1985, 'kelly'));
const calcAverage = (a, b, c) => (a+b+c)/3
function checkWinner(avgDolphins, avgKoalas){
console.log(avgDolphins, avgKoalas)
if(avgDolphins >= avgKoalas*2) console.log(`avgDolphins won (${avgDolphins} vs ${avgKoalas})`)
else if(avgKoalas >= avgDolphins*2) console.log(`avgKoalas won (${avgKoalas} vs ${avgDolphins})`)
else console.log('No team has won');
}
const avgDolphins = calcAverage(44, 23, 71)
const avgKoalas = calcAverage(65, 54, 49)
// const avgDolphins = calcAverage(85, 54, 41)
// const avgKoalas = calcAverage(23, 34, 27)
checkWinner(avgDolphins, avgKoalas)
const friends = new Array('rams', 'sudeepth', 'laddu', 'kiran')
console.log(friends);
console.log(friends.length);
const years = [1990, 1991, 1992, 1993]
years[4] = 1994
console.log(years);
years[2] = 1981
console.log(years);
console.log(years[3])
const myProps = ['praveen', 'sana', 2030-1991, friends]
console.log(myProps);
const newLength = friends.push('paramesh')
console.log(newLength, friends);
const reverseString = ipText => {
let newStirng = ''
for(let i=ipText.length-1; i >=0; i--){
newStirng+=ipText[i]
}
return newStirng
}
console.log(reverseString('praveen'));
const myObject = {
firstName:'Praveen',
lastName: 'Sana',
age: 2021-1991,
profession: 'Software Developer',
company: 'Societe Generale',
collegues: ['soji', 'don', 'ajith', 'vittal'],
hasDrivingLicense: false,
salary: (gross, pf, tax) => {
return gross-pf-tax
},
eligibleForDate: function(){
this.dateAge = this.age > 19 ? true: false
return this.dateAge
}
}
console.log(myObject);
console.log(myObject.eligibleForDate()+' =====================eligibledate====================');
console.log(myObject.dateAge+' =====================eligibledate====================');
console.log('Age: '+myObject.age)
console.log('My buddy in team '+myObject.collegues[3])
myObject.twiiterHandle = '@praveensana'
console.log(myObject);
// const inputQuestion = prompt('What do you want from me as an object')
// if(myObject[inputQuestion]){
// console.log(myObject[inputQuestion])
// }
// else{
// console.log('No property found with the entered value, please enter correct property');
// }
console.log('My Net salary: '+myObject.salary(75000, 4500, 2300))
const license = () => myObject.hasDrivingLicense ? 'a' : 'no'
console.log(`${myObject.firstName} is a ${myObject.age} years old and he has ${license()} driving license`);
function calAvg(arr){
let sum = 0
for(let i=0; i<arr.length; i++){
sum= sum+arr[i]
}
return sum/arr.length
}
console.log(calAvg([6, 3, 1]));
const convertKelvin = function(){
const measurement = {
type:'temp',
units:'celsius',
value:prompt('Enter degrees celsius: ')
}
const kelvin = measurement.value + 273
return kelvin
}
console.log('converted temperature '+convertKelvin());
const printForecast = (arr) => {
let output = ''
for(let i=0; i<arr.length; i++){
output = output+` ... ${arr[i]}^c in ${i+1} days `
}
return output
}
console.log(printForecast([17, 21, 23]))
console.log(printForecast([12, 5, -5, 0, 4]))