0% found this document useful (0 votes)
8 views3 pages

JavaScript Problem Solving Exercises

The document presents five JavaScript programming problems, each requiring the implementation of specific functions. The problems include calculating the smaller angle between clock hands, checking if a year is a leap year, determining if a number is perfect, reversing a number, and checking if one string is a substring of another. Each problem provides input and output formats along with constraints and examples.

Uploaded by

Sahil Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

JavaScript Problem Solving Exercises

The document presents five JavaScript programming problems, each requiring the implementation of specific functions. The problems include calculating the smaller angle between clock hands, checking if a year is a leap year, determining if a number is perfect, reversing a number, and checking if one string is a substring of another. Each problem provides input and output formats along with constraints and examples.

Uploaded by

Sahil Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript Problem Solving

Q1. Find the Smaller Angle


PrepBuddy has an analog clock which consists of two hands one for hour and another for minute. She wants to calculate the
shorter angle formed between hour and minute hand at any given time.
Note: You have to complete Minimal_Angle function. No need to take any input.

Input Format

The input contains two number h and m, which represents the current time as hour and minutes.

Output Format
Return the Minimal angle formed between the Hour hand and Min ute hand.

Constraints
All valid times

Example

Sample Input 1
5 30
Sample Output 1
15
Sample Input 2
60
Sample Output 2
180

Q2. Check whether the year is Leap year or not.

Write a program which takes an year N as input from the user and find out whether the given year is a Leap Year or not.
Note: You have to complete Check_Leap function. No need to take any input.

Input Format

The input contains a single number N, which represents a year.

Output Format
Return "Leap Year" if the given year is a Leap Year else return "Non Leap Year".

Constraints

1000≤N≤10000

Example

Sample Input 1
1900
Sample Output 1
Non Leap Year
Sample Input 2
2012
Sample Output 2
Leap Year
Q3. Perfect Number Check.
Have you heard of Perfect numbers? If not let me tell you what is it, Perfect Numbers are integers that are equal to the sum
of all its divisors except that number itself.
Now, You are given an integer N, write a program to check whether the given number is a Perfect Number or not.
Note: You have to complete Perfect _Check function. No need to take any input.

Input Format

The input contains a single number N.

Output Format
Return "YES" if the number is a Perfect Number, else return "NO".

Constraints

1≤N≤100000

Example

Sample Input 1
1
Sample Output 1
YES
Sample Input 2
96345
Sample Output 2
NO

Q4. Reverse a Number.

Write a program which takes a numebr N as input from the user and You need to reverse the number.
Note: You have to complete Reverse_Number function. No need to take any input.

Input Format

The input contains a single number N.

Output Format
Return the reversed number.

Constraints

1≤N≤100000

Example
Sample Input 1
1900
Sample Output 1
91
Sample Input 2
2012
Sample Output 2
2102
Q5. Substring Check.

You are given two strings S1 and S2, you need to check whether the string S1 is a substring of string S2 or not.
Note: You have to complete Substring_Check function. No need to take any input.

Input Format

The first line of input contains the first string S1. The second line of input contains the second string S2.

Output Format

Return "YES" if S1 is a substring of S2 else return "NO".

Constraints

1≤|S1|,|S2|≤100, where |S|denotes the length of string S.

Example

Sample Input 1
Hii this is Prepbuddy Prepbuddy
Sample Output 1
YES
Sample Input 2
Hii this is Prepbuddy Prepbytes
Sample Output 2
NO

You might also like