Page 155 - Computer Software Application TP - Volume 1
P. 155

COMPUTER SOFTWARE APPLICATION - CITS




           1  Write a JavaScript program that takes a person’s age as input and determines whether they are eligible for
              voting. If the age is 18 or above, the function should return “Eligible for voting,” otherwise, it should return “Not
              eligible for voting.” Use if-else statements to implement the logic
           2  Develop a JavaScript program that takes a year as input and determines whether it is a leap year or not. If the
              year is divisible by 4 but not by 100, or if it is divisible by 400, it is considered a leap year.

           3  Write a JavaScript program that takes two numbers as input and display the maximum of the two. Use if-else
              statements to implement the comparison.
           4  Create a JavaScript program that takes a number representing a month (1 for January, 2 for February, etc.) and
              prints the corresponding season. Consider the following mappings: 1-3 (Winter), 4-6 (Spring), 7-9 (Summer),
              10-12 (Fall). Use if-else-if statements to implement this logic.

           5  Create a JavaScript program that takes a student’s score as input and determines their grade. If the score is
              greater than or equal to 90, assign the grade ‘A’; if between 80 and 89, assign ‘B’; if between 70 and 79, assign
              ‘C’; if between 60 and 69, assign ‘D’; otherwise, assign ‘F’. By Using if-else-if statements.
           6  Write  a  JavaScript  program  that  takes  three  numbers  as  input  and  determines  the  largest  among  them.
              However, if two or more numbers are equal, display a message indicating that there is a tie, using nested if-
              else statements.
           7  Write a JavaScript program that takes a grade (A, B, C, D, F) as input and shows message indicating the
              corresponding description (excellent, good, average, poor, fail). Use a switch statement to implement this
              logic.
           8  Create a JavaScript program that takes a month’s number (1 for January, 2 for February, etc.) as input and
              returns the name of the month. Use a switch statement to implement this logic.
           9  Develop a JavaScript program that generates the Fibonacci sequence up to a given number of terms using
              a for loop. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the two
              preceding ones.
           10 Write a JavaScript program that takes a number and then prints its multiplication table up to 10 using a for loop.
           11 Create  a  JavaScript  program  that  takes  a  positive  integer  as  input  and  determines  whether  it  is  a  prime
              number or not. Use a while loop to implement the prime number checking algorithm.
           12 Write a JavaScript program that calculates the sum of digits of a given number. Use a while loop to extract
              digits one by one until the number becomes zero, and accumulate the sum.
           13 Develop a JavaScript program that calculates the factorial of a given number using a do-while loop. The
              factorial of a number n is the product of all positive integers less than or equal to n.


































                                                           140
                               CITS : IT & ITES - Computer Software Application - Exercise 39
   150   151   152   153   154   155   156   157   158   159   160