week-8
week-8
a. Write a program which asks the user to enter three integers, obtains the numbers from the user
and outputs HTML text that displays the larger number followed by the words “LARGER NUMBER”
in an information message dialog. If the numbers are equal, output HTML text as “EQUAL
NUMBERS”.
Aim: To Write a program which asks the user to enter three integers, obtains the numbers from the
user and outputs HTML text that displays the larger number followed by the words “LARGER
NUMBER” in an information message dialog. If the numbers are equal, output HTML text as “EQUAL
NUMBERS”.
Source code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script>
function findLargestNumber() {
alert("EQUAL NUMBERS");
} else {
</script>
</head>
<body>
<h1>JavaScript Conditional Statements and Loops</h1>
</body>
</html>
OUTPUT:
RESULT:
The above program which asks the user to enter three integers, obtains the numbers from the user
and outputs HTML text that displays the larger number followed by the words “LARGER NUMBER” in
an information message dialog. If the numbers are equal, output HTML text as “EQUAL NUMBERS” is
successfully executed.
SOURCE CODE
function getWeekDay(dayNumber) {
switch (dayNumber) {
case 1:
console.log("Sunday");
break;
case 2:
console.log("Monday");
break;
case 3:
console.log("Tuesday");
break;
case 4:
console.log("Wednesday");
break;
case 5:
console.log("Thursday");
break;
case 6:
console.log("Friday");
break;
case 7:
console.log("Saturday");
break;
default:
// Example usage
getWeekDay(i);
OUTPUT
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Result: The above program to display week days using switch case was successfully Executed.
c. Write a program to print 1 to 10 numbers using for, while and do-while loops
AIM:To Write a program to print 1 to 10 numbers using for, while and do-while loops
Source code:
console.log(i);
let j = 1;
console.log(j);
j++;
let k = 1;
do {
console.log(k);
k++;
10
10
5
6
10
RESULT:
The above program to print 1 to 10 numbers using for, while and do-while loops is successfully
executed.
d. Write a program to print data in object using for-in, for-each and for-of loops
AIM: To Write a program to print data in object using for-in, for-each and for-of loops
Source code:
const person = {
name: "John",
age: 30,
};
console.log(`${key}: ${person[key]}`);
console.log(`${key}: ${value}`);
});
console.log(`${key}: ${value}`);
Output:
name: John
age: 30
name: John
age: 30
name: John
age: 30
RESULT: The above program to print data in object using for-in, for-each and for-of loops was
successfully executed.
SOURCE CODE:
function isArmstrongNumber(num) {
let sum = 0;
// Example usage
if (isArmstrongNumber(number)) {
} else {
OUTPUT:
RESULT: The above program to determine whether a given number is an ‘ARMSTRONG NUMBER’ or
not was successfully executed.
F. Write a program to display the denomination of the amount deposited in the bank in terms of
100’s, 50’s, 20’s, 10’s, 5’s, 2’s & 1’s. (Eg: If deposited amount is Rs.163, the output should be 1-
100’s, 1-50’s, 1- 10’s, 1-2’s & 1-1’s)
AIM:To Write a program to display the denomination of the amount deposited in the bank in terms
of 100’s, 50’s, 20’s, 10’s, 5’s, 2’s & 1’s.
SOURCE CODE:
function getDenominations(amount) {
return result;
// Example usage
console.log(`${count} - Rs.${denom}`);
OUTPUT:
1 - Rs.1
1 - Rs.2
1 - Rs.10
1 - Rs.50
1 - Rs.100
RESULT: The above program to display the denomination of the amount deposited in the bank in
terms of 100’s, 50’s, 20’s, 10’s, 5’s, 2’s & 1’s was successfully executed.