-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp4.html
105 lines (81 loc) · 3.59 KB
/
p4.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JS-Conditions</title>
</head>
<body>
<h1>Conditional Statements</h1>
<h2>there are 4 Conditional Statements</h2>
<ol>
<li>if</li>
<li>if...else</li>
<li>if...else if.....else</li>
<li>switch</li>
</ol>
<p>prompt(); - function- for asking question to user - User Input <br>
alert(); -function-for saying something - Shows the alert Box</p>
<p><u>Number.parseInt()</u> Method is used to convert the string into number.</p>
<h2>JS Turnary Operators. Syntax:- (condition)? statement1 : statement2; </h2>
<script>
// 1. If Statement:
// a) Write a JavaScript function that takes a number as input and returns "Positive" if it's greater than zero, "Negative" if it's less than zero, and "Zero" if it's equal to zero.
function numberComparison(num){
if(num>0){
console.log("Number is Positive");
}
if(num<0){
console.log("Number is Negative")
}
if(num==0){
console.log("Number is Zero")
}
}
numberComparison(-7);
// b) Create a function that takes a string as input and checks if it starts with the letter "A". If it does, return "Starts with A", otherwise return "Does not start with A".
function stringComp(letter){
if(letter[0] == "A"){
console.log("The word " + letter + " Starts with a")
}else{
console.log("The word " + letter + " Does not sart with a")
}
}
stringComp("Ayaz")
// 2. If-Else Statement:
// a) Write a JavaScript function that takes a number as input and returns "Even" if it's divisible by 2, and "Odd" if it's not.
const jsFunc=(number)=>{
if(number%2==0){
console.log("The Number " + number + " Is Even")
}else{
console.log("The number is Odd")
}
}
jsFunc(4);
// b) Create a function that takes a string as input and checks if it has more than 10 characters. If it does, return "Long string", otherwise return "Short string".
const strComp=(str1)=>{
if(str1.length>10){
console.log("Long String")
}else{
console.log("Short string")
}
}
strComp("shgei2i22i2ilhj")
// 3. Nested If-Else Statement:
// a) Write a JavaScript function that takes three numbers as input and returns the largest number.
function numbComp(a,b,c){
if(a > b && a > c){
console.log("a is a large number")
}
if (b > a && b > c) {
console.log("b is the large number")
}
if(c > a && c > b){
console.log("c is the large number")
}
}
numbComp(100,999,5999);
// b) Create a function that takes a string as input and checks if it contains both uppercase and lowercase letters. If it does, return "Mixed case", otherwise return "Not mixed case".
</script>
</body>
</html>