-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
168 lines (128 loc) · 3.88 KB
/
script.js
File metadata and controls
168 lines (128 loc) · 3.88 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
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
//Program No. 1
//Finding The Largest Number:-
function largest()
{
console.log("Program No. 1");
console.log("Finding The Largest Number:-");
let num1 = 5, num2 = 8, num3 = 3; //variables
//printing Numbers to the Console
console.log("The Numbers are:- "+num1+", "+num2+", "+num3);
//if else statement for Logic
if (num1>num2 && num1>num3) //checking for num1
{
console.log("The Largest Number is: "+ num1);
}
else if (num2>num1 && num2>num3) //checking for num2
{
console.log("The Largest Number is: "+ num2);
}
else // here num3 will print if upper else if statement are false
{
console.log("The Largest Number is: "+ num3);
}
}
largest(); //calling the function
console.log("**************************************************************"); //separating the Above Program
// Program No. 2
//Finding the Factorial of a number
function factorial()
{
console.log("Program No. 2");
console.log("Finding the Factorial of a number:-");
let numberForFact = 5, fact=1; //Variables
console.log("Number is: "+numberForFact); //printing The number on console
if(numberForFact === 0) //checking for if the number is equal to zero
{
console.log("Factorial of the number is: 1");
}
else{
for(let i = 1;i<=numberForFact;i++) //logic for finding the factorial of a number
{
fact = fact * i;
}
console.log("The Factorial of the number is: "+fact); //printing the result on console
}
}
factorial(); //calling the Funtion
console.log("**************************************************************"); //separating the Above Program
// Program No. 3
// Checking The Number positive, negative or zero
function numberPositive()
{
console.log("Program No. 3");
console.log("Checking the Number is Positive, Negative or Zero:-");
let number = -4 //variable
console.log("The Number is: "+number); //printing the number on console
//logic
if(number === 0) //checking for zero
{
console.log("The Number is Zero");
}
else if(number>0) //checking for positive number
{
console.log("The Number is Positive");
}
else //for printing negative if the upper else if statement is false
{
console.log("The Number is Negative");
}
}
numberPositive(); //calling the Function
console.log("**************************************************************"); //separating the Above Program
//Program No. 4
// Checking the number is prime or not
function checkingPrimeNumber()
{
console.log("Program No. 4");
console.log("Checking the number is prime r not:-");
const checkNumber = 2;
let isPrime = true;
//printing the number on console
console.log("The Number is: "+checkNumber);
// checking if number is equal to 1
if (checkNumber === 1)
{
console.log("1 is neither prime nor composite number.");
}
// checking if number is greater than 1
else if (checkNumber > 1) {
//logic
for (let i = 2; i < checkNumber; i++)
{
if (checkNumber % i == 0) {
isPrime = false;
break;
}
}
if (isPrime)
{
console.log(`The number is a prime number`);
} else {
console.log(`The number is a not prime number`);
}
}
// checking if number is less than 1
else
{
console.log("The number is not a prime number.");
}
}
checkingPrimeNumber(); //Calling the Function
console.log("**************************************************************"); //separating the Above Program
// Program No. 5
// program to generate a multiplication table
function multi()
{
console.log("Program No. 5");
console.log("Printing the Multiplication Table:-");
let number = 19;
console.log(`The Number is: ${number}`);
//creating a multiplication table
for(let i = 1; i <= 10; i++)
{
const result = i * number;
console.log(`${number} * ${i} = ${result}`);// Printing the result on console
}
}
multi(); //calling the function
console.log("**************************************************************"); //separating the Above Program