-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJS_HW_2.js
More file actions
97 lines (89 loc) · 2.62 KB
/
Copy pathJS_HW_2.js
File metadata and controls
97 lines (89 loc) · 2.62 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
/*
Create a variable "age_1" and assign the value 10 to it
Create variable “age_2” and assign value 18 to it
Create variable “age_3” and assign value 60 to it
Create an if in which you will check the value of the variable age_1
If age_1 < age_2, print to console “You don’t have access cause your age is” + age_1 + “It’s less then”
If age_1 >= age_2 and age_1 < age_3, output “Welcome!”
If age_1 > age_3, output “Keep calm and look Culture channel” to the console
Otherwise print "Technical work"
*/
/* .1*
Convert the written tasks above into a function that takes age as input
Example:const checkAge = function(age) {
Your transformations
}
Output to the console the result of the function with ages 17, 18, 61
*/
const checkAge1 = function(age){
if(age < 18) {
console.log("You don't have access 'cause your age is " + age + " It's less than " + 18)
}
else if (age >= 18 && age < 61) {
console.log("Welcome!")
}
else if (age > 60) {
console.log("Keep calm and look Culture channel")
}
else {
console.log("Invalid input")
}
}
checkAge1(17)
checkAge1(18)
checkAge1(61)
checkAge1()
/* .2*
Convert assignment 1* so that the data type is checked first in the function
And if it is not a number, an error was thrown
*/
const checkAge2 = function(age){
if (!age || (typeof (age) != "number")) {
console.log("Invalid input")
}
else if(age < 18) {
console.log("You don't have access 'cause your age is " + age + " It's less than " + 18)
}
else if (age >= 18 && age < 61) {
console.log("Welcome!")
}
else if (age > 60) {
console.log("Keep calm and look Culture channel")
}
}
checkAge2('qwe')
checkAge2('')
checkAge2(true)
checkAge2(false)
checkAge2('2')
checkAge2(17)
checkAge2(18)
checkAge2(61)
/* .3*
Convert 2* so the value '2' (the string containing ONLY a NUMBER)
was skipped when converted to a number
*/
const checkAge3 = function(age){
age = Number(age)
if (age && !isNaN(age) && age != true && age != false) {
if (age < 18) {
console.log("You don't have access 'cause your age is " + age + " It's less than " + 18)
}
else if (age >= 18 && age <= 60) {
console.log("Welcome!")
}
else if (age > 60) {
console.log("Keep calm and look Culture channel")
}
}
else console.log("Invalid input")
}
checkAge3('qwe')
checkAge3('')
checkAge3(true)
checkAge3(false)
checkAge3('2')
checkAge3(17)
checkAge3(18)
checkAge3(61)
checkAge3(0)