Domain Fundamentals Assignments
Domain Fundamentals Assignments
1. Accept a char input from the user and display it on the console.
2. Accept two inputs from the user and output their sum.
Number 1 Integer
Number 2 Float
Sum Float
a. Program should accept 3 inputs from the user and calculate simple interest for
the given inputs. Formula: SI=(P*R*n)/100)
a. Program should accept an input from the user and output a message as
“Passed” or “Failed”
mark float
a. Program should accept an input from the user and display their grade as
follows
Mark Grade
> 90 A
80-89 B
70-79 C
60-69 D
50-59 E
< 50 Failed
6. Using the ‘switch case’ write a program to accept an input number from the user and
output the day as follows.
Input Output
1 Sunday
2 Monday
3 Tuesday
4 Wednesday
5 Thursday
6 Friday
7 Saturday
var choice
=parseInt(prompt("1.Sunday\n2.Monday\n3.Tuesday\n4.Wednesday\n5
.Thursday\n6.Friday\n7.Saturday\nEnter your choice : "));
switch(choice){
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:
console.log("Invalid entry");
break;
}
a. Accept an input from the user and display its multiplication table
Eg:
Input: 5
Output:
1x5=5
2 x 5 = 10
3 x 5 = 15
4 x 5 = 20
5 x 5 = 25
6 x 5 = 30
7 x 5 = 35
8 x 5 = 40
9 x 5 = 45
10 x 5 = 50
8. Write a program to find the sum of all the odd numbers for a given limit
a. Program should accept an input as limit from the user and display the sum
of all the odd numbers within that limit
Input: 10
}
console.log("Sum is "+sum);
9. Write a program to print the following pattern (hint: use nested loop)
12
123
1234
12345
var pattern=""
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
pattern+=j;
}
pattern+="\n"
}
console.log(pattern);
Input: 5
a. Program should accept an array and display the number of even numbers
contained in that array
Input: 5
a. Program should accept and array, sort the array values in descending order
and display it
Input: 5
Input: MALAYALAM
Input: HELLO
Input: 3
Input:
123
456
789
Input:
10 20 30
40 50 60
70 80 90
11 22 33
44 55 66
77 88 99
main()
1. Declare an array
2. Call function getArray()
3. Call function displayArray()
getArray()
displayArray()
a. Program should accept an input from the user and display whether the
number is prime or not
Input: 7
17. Write a menu driven program to do the basic mathematical operations such as
addition, subtraction, multiplication and division (hint: use if else ladder or switch)
class Operations {
constructor(numa,numb){
this.num1 = numa
this.num2 = numb
}
addition(numa,numb){
return numa + numb
}
subtraction(numa,numb){
return numa - numb
}
multiplication(numa,numb){
return numa * numb
}
division(numa,numb){
return numa / numb
}
}
let newOperations = new Operations();
let num1 = parseInt(prompt("enter first number:"))
let num2 = parseInt(prompt("enter second number:"))
let sum
let ch
=parseInt(prompt("1.addition\n2.subtraction\n3.multiplication\n
4.division\nEnter your choice: "))
switch(ch){
case 1:
sum = newOperations.addition(num1,num2);
break;
case 2:
sum = newOperations.subtraction(num1,num2);
break;
case 3:
sum = newOperations.multiplication(num1,num2);
break;
case 4:
sum = newOperations.division(num1,num2)
break;
default:
console.log("invalid entry")
break;
}
console.log("result = "+sum);
18. Grades are computed using a weighted average. Suppose that the written test
counts 70%, lab exams 20% and assignments 10%.
Written test = 81
Lab exams = 68
Assignments = 92
Write a program to find the grade of a student during his academic year.
a. Program should accept the scores for written test, lab exams and
assignments
b. Output the grade of a student (using weighted average)
Eg:
Written test = 55
Lab exams = 73
Assignments = 87
Eg 1:
Enter the annual income
495000
Income tax amount = 24750.00
Eg 2:
Enter the annual income
500000
Income tax amount = 25000.00
2 3
4 5 6
7 8 9 10
let n = 5
let string = "";
let num = 1;
for (let i = 1; i < n; i++) {
for (let j = 1; j <= i; j++) {
string += " "+num;
num++
}
string += "\n";
}
console.log(string);
21.
21. Write a program to multiply the adjacent values of an array and store it in an
another array
Eg:
1 2 3 4 5
Output
2 6 12 20
main()
getArray()
getArray()
displayArray()
Eg:
2
Enter the values of array 1
1 2
3 4
5 6
7 8
Output:
6 8
10 12
main()
1. Declare an array
2. Call function getArray()
3. Call function displayArray()
getArray()
displayArray()
1. Display the array values
Eg:
1 2 3
4 5 6
7 8 9
1 2 3
4 5 6
7 8 9
24. Write a menu driven program to calculate the area of a given object.
circle() {
square() {
rectangle() {
triangle() {
}
}
Class Area{
circle(){
square(){
rectangle() {
triangle() {
Eg 1:
1. Circle
2. Square
3. Rectangle
4. Triangle
2
Enter the length
Output
Eg 2:
1. Circle
2. Square
3. Rectangle
4. Triangle
Output
let area
class Area {
circle(){
let radius = parseInt(prompt("Enter radius: "))
area = 3.14 * radius * radius
return area
}
square(){
let width = parseInt(prompt("Enter the length:"))
area = width * width
return width
}
rectangle(){
let length = parseInt(prompt("Enter the length:"))
let breadth = parseInt(prompt("Enter the breadth:"))
area = length * breadth
return area
}
triangle(){
let length = parseInt(prompt("Enter the length:"))
let height = parseInt(prompt("Enter the height:"))
area = .5 * length * height
return area
}
}
class MyClass extends Area{
}
let obj = new MyClass();
let ch =
parseInt(prompt("1.Circle\n2.Square\n3.Rectangle\n4.Triangle\nEnte
r your choice: "))
switch(ch){
case 1:
obj.circle()
break;
case 2:
obj.square()
break;
case 3:
obj.rectangle()
break;
case 4:
obj.triangle()
break;
default:
console.log("Invalid entry")
break;
}
console.log("Area = "+area);
25. Write a Javascript program to display the status (I.e. display book name, author
name & reading status) of books. You are given an object library in the code's template. It
contains a list of books with the above mentioned properties.Your task is to display the
following:
var library = [
},
readingStatus: true
},
readingStatus: false
];
var library = [
{
title: 'Bill Gates',
author: 'The Road Ahead',
readingStatus: true
},
{
title: 'Steve Jobs',
author: 'Walter Isaacson',
readingStatus: true
},
{
title: 'Mockingjay: The Final Book of The Hunger Games',
author: 'Suzanne Collins',
readingStatus: false
}
];
let ch = prompt("1.Bill Gates\n2.Steve
Jobs\n3.Mockingjay\nEnteryour choice")
if(library[ch-1].readingStatus == true){
console.log("Already read '"+library[ch-1].title+"'
by'"+library[ch-1].author+"'")
}else{
console.log("You still need to read '"+library[ch-1].title+"'by
'"+library[ch-1].author+"'")
}
26. Given a variable named my_string, try reversing the string using
my_string.split().reverse().join() and then print the reversed string to the console. If the try
clause has an error, print the error message to the console. Finally, print the typeof of the
my_string variable to the console.
Output format:
Error : ${err.message}
Eg:
a) Sample Input 0
"1234"
Sample Output 0
b) Sample Input 1
Number(1234)
Sample Output 1
conditions:
● notANumberError- When userHeight is NaN
● HugeHeightError – When userHeight is greater than 200
● TinyHeightError - When userHeight is less than 40
Eg:
a) Sample Input 0
test
Sample Output 0
notANumberError
b) Sample Input 1
250
Sample Output 1
hugeHeightError
c) Sample Input 2
0
Sample Output 2
tinyHeightError
d) If userHeight is valid print ‘valid’
29. Write a myFilter function that takes 2 parameters: myArray and callback. Here,
myArray is an array of numbers and callback is a function that takes the elements of
myArray as its parameter and returns a boolean true if the sum of the number is even or
false if the sum of the number is odd.
a) Sample Input
12345
b) Sample Output
15
let sum = 0
function myFilter(array,call){
for(let i=0;i < array.length;i++){
sum = sum + array[i]
}
}
let callback = (s) => s % 2
let myArray = [1,2,3,4,5]
myFilter(myArray,callback)
console.log(sum)