-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathas2.js
More file actions
103 lines (87 loc) · 2.83 KB
/
as2.js
File metadata and controls
103 lines (87 loc) · 2.83 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
// 1. Write a Javascript function to check whether a triangle is equilateral,
// isosceles or scalene
let triangle =(Side1,Side2,Side3) => {
if(Side1===Side2 && Side2===Side3){
console.log("It is an Equilateral Triangle")
}
else if(Side1===Side2 && Side2!==Side3 || Side1===Side3 && Side1!==Side2){
console.log("It is an Isosceles Triangle")
}
else if(Side1!==Side2 && Side2!==Side3){
console.log("It is an Scalene Triangle")
}
}
triangle(5,3,4)
// 2. Write a function using switch case to find the grade of a student based
// on marks obtained
// a. “S grade” if the marks are between 90 and 100.
// b. “A grade” if the marks are between 80 and 90.
// c. “B grade” if the marks are between 70 and 80.
// d. “C grade” if the marks are between 60 and 70.
// e. “D grade” if the marks are between 50 and 60.
// f. “E grade” if the marks are between 40 and 50.
// g. “Student has failed” if the marks are between 0 and 40.
// h. Else output “Invalid marks”.
function Grading(score) {
switch(true) {
case (score <= 100 && score >= 90):
console.log("S grade");
break;
case (score <= 89 && score >= 80):
console.log("A grade");
break;
case (score <= 79 && score >= 70):
console.log("B grade");
break;
case (score <= 69 && score >= 60):
console.log("C grade");
break;
case (score <= 59 && score >= 50):
console.log("D grade");
break;
case (score <= 49 && score >= 40):
console.log("E grade");
break;
case (score < 40 && score >= 0):
console.log("Student has failed");
break;
default:
console.log('INVALID SCORE');
}
};
Grading(-10);
// 3. Write a JavaScript program to find the sum of the multiples of 3 and 5
// under 1000
//
sum = 0
for(let i = 1;i<=1000;i++){
if(i%3===0 && i%5===0){
sum = sum+i
}
}
console.log(sum)
//4. Write a program to find the factorial of all prime numbers between a
// given range . Range will be passed as 2 values in the function
// parameters. eg- if it is needed to find the values for numbers 1-100, then
// function declaration can look like - function prime(1,100).
let factorial = (r1,r2)=>{
for (let i = r1; i <= r2; i++) {
let flag = 0;
var fact = 1
// looping through 2 to user input number
for (let j = 2; j < i; j++) {
if (i % j === 0) {
flag = 1;
break;
}
}
// if number greater than 1 and not divisible by other numbers
if (i > 1 && flag == 0) {
for(let k = i; k >0;k--){
fact =fact*k
}
console.log(`factorial of ${i} is = `,fact)
}
}
}
factorial(1,20)