JS-Test
JS-Test
GROUP – A
A) 2
B) "11"
C) NaN
D) Error
Answer: B) "11"
Explanation: JavaScript converts the number to a string and concatenates it with "1".
2. What is the default value of a variable declared with let but not initialized?
A) null
B) undefined
C) 0
D) NaN
Answer: B) undefine
Explanation: let variables that are declared but not initialized are undefined.
A) true
B) false
C) Error
D) undefined
Answer: A) true
Explanation: x == "10" is true because the == operator performs type coercion, and y == 20 is true.
A) 2
B) 1
C) 0
D) NaN
Answer: B) 1
Explanation: The modulus operator (%) returns the remainder of division (5 % 2 is 1).
A) 5
B) undefined
C) Error
D) Na
Answer: A) 5
Explanation: The arrow function foo returns 5.
Explanation: The do...while loop guarantees at least one iteration before the condition is checked.
A) [1, 2]
B) {a: 1, b: 2}
C) ["a", "b"]
D) undefined
Answer: A) [1, 2]
End of Group - A
JavaScript Test
Group - B
Easy Coding Questions- (Choose any Two) (15 Marks Each) Total 30 Marks
1. Add Two Numbers (This problem helps you understand basic arithmetic and how to handle input and output in JavaScript.)
Problem Description
You are given two integers. Your task is to calculate and return their sum.
For example:
Example
Input:
Output:
Function Description
Function Signature:
• Parameters:
• Returns:
An integer, the sum of a and b.
Input Format
Output Format
Constraints
2. Check If a String is Empty (This problem introduces you to string manipulation and basic conditional statements.)
Problem Description
You are given a string, and your task is to check if the string is empty. An empty string is a string with no
characters (length 0). Return true if the string is empty, otherwise return false.
For example:
• Input: ""
Output: true
• Input: "hello"
Output: false
Example
Input:
Output:
Function Description
Function Signature:
• Parameters:
Input Format
Output Format
Constraints
3. Print Even Numbers in Range (This problem introduces the concept of loops and conditional checks.)
Problem Description
For example:
Example
Input:
Output:
Function Description
Function Signature:
• Parameters:
• Returns:
A string containing space-separated even numbers from 1 to n.
Input Format
A single integer n.
Output Format
Constraints
You are given an integer. Your task is to calculate and return its square.
For example:
• Input: 4
Output: 16
Example
Input:
Output:
Function Description
Function Signature:
• Parameters:
• Returns:
An integer, the square of the given number.
Input Format
Output Format
Constraints
5. Convert Celsius to Fahrenheit (This problem helps you practice arithmetic and working with floating-point numbers.)
Problem Description
You are given a temperature in Celsius. Your task is to convert it to Fahrenheit using the formula:
For example:
• Input: 25
Output: 77
Example
Input:
Output:
Function Description
Function Signature:
• Parameters:
• Returns:
A floating-point number, the equivalent temperature in Fahrenheit.
Input Format
Output Format
Constraints
You are given a year. Your task is to determine whether it is a leap year.
1. It is divisible by 4.
2. However, if the year is divisible by 100, it is not a leap year. Unless it is also divisible by 400.
For example:
• Input: 2024
Output: true
• Input: 1900
Output: false
Example
Input:
Output:
Function Description
Function Signature:
• Parameters:
• Returns:
A boolean value: true if the year is a leap year, otherwise false.
Input Format
Output Format
Constraints
End of Group - B
JavaScript Test
Group - C
Medium Coding Questions (Choose any two) (25 Marks Each) Total 50 Marks
1. Reverse a String (This problem helps you understand string manipulation and how to use loops effectively in JavaScript.)
Problem Description
You are given a string. Your task is to reverse the string and return it.
For example:
• Input: "hello"
Output: "olleh"
This problem helps you understand string manipulation and how to use loops effectively in JavaScript.
Example
Input:
Output:
Function Description
Function Signature:
• Parameters:
• Returns:
A string, which is the reverse of the input.
Input Format
Constraints
2. Find Prime Numbers in Range (This problem helps you practice working with loops and functions to determine prime numbers.)
Problem Description
You are given an integer n. Your task is to find all prime numbers up to n (inclusive).
For example:
• Input: 10
Output: 2, 3, 5, 7
This problem helps you practice working with loops and functions to determine prime numbers.
Example
Input:
Output:
Function Description
Function Signature:
• Parameters:
▪ n: An integer representing the upper limit of the range.
• Returns:
A string of space-separated prime numbers from 1 to n.
Input Format
A single integer n.
Output Format
Constraints
3. Capitalize Each Word in a String (This problem helps you understand string manipulation and the use of functions in JavaScript.)
Problem Description
You are given a string. Your task is to capitalize the first letter of each word in the string.
For example:
Example
Input:
Output:
Function Description
Function Signature:
• Parameters:
• Returns:
A string with the first letter of each word capitalized.
Input Format
Output Format
4. Sum of Digits in a Number (This problem helps you understand how to extract digits from a number using loops.)
Problem Description
You are given an integer. Your task is to calculate the sum of its digits.
For example:
• Input: 123
Output: 6
This problem helps you understand how to extract digits from a number using loops.
Example
Input:
Output:
Function Description
Function Signature:
• Parameters:
▪ num: An integer whose digits need to be summed.
• Returns:
An integer, the sum of the digits of the given number.
Input Format
Output Format
5. Sort an Array (This problem helps you understand arrays and basic sorting algorithms or built-in methods in JavaScript.)
Problem Description
You are given an array of integers. Your task is to sort the array in ascending order.
For example:
• Input: [4, 2, 9, 1]
Output: [1, 2, 4, 9]
Example
Input:
Output:
Function Description
Function Signature:
• Parameters:
▪ arr: An array of integers to be sorted.
• Returns:
An array of integers sorted in ascending order.
Input Format
Output Format
6. Count Occurrences of a Character (This problem helps you understand how to work with strings and loops in JavaScript.)
Problem Description
You are given a string and a character. Your task is to count how many times the character appears in the
string.
For example:
Example
Input:
Output:
Function Description
Function Signature:
• Parameters:
▪ str: A string to search within.
• Returns:
An integer, the count of the character in the string.
Input Format
Output Format
Constraints
End of Group - C