Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 2.76 KB

23-basic-test-exercise.md

File metadata and controls

47 lines (35 loc) · 2.76 KB
  1. Print below pattern:
1
23
456
78910
1112131415
  1. Create a JavaScript program that prompts the user to enter their age. If the age entered is less than 18, display an alert box with the message "Sorry, you must be at least 18 years old to access this website." If the age entered is between 18 and 30, display a confirm box with the message "Are you sure you want to proceed?" If the user clicks "Cancel" in the confirm box, display an alert box with the message "Action canceled." If the user clicks "OK" in the confirm box, display a prompt box asking for their name and display an alert box with the message "Welcome, [Name]!" (replace [Name] with the name entered).

  2. Create a JavaScript program that calculates the average of three numbers. Prompt the user to enter three numbers and display the average using an alert box.

  3. Solve below expressions

  • 5 + 2 * 3 - 4 / 2
  • 10 % 3 + 4 * 2 / 5
  • 15 % (7 + 3) - 4 * 2
  • (2 + 3) * (4 - 1) + 6 / 2
  • 12 / 3 + 4 - 2 * 5
  1. Explain the difference between the == and === operators in JavaScript, and provide an example where their behavior differs.

  2. Explain the difference between the slice and substring operators in JavaScript, and provide an example where their behavior differs.

  3. Write a JavaScript program that prompts the user to enter their age and their country of residence. Based on the age and country, display a message using if-else if-else statements and logical operators. Consider the following conditions:

If the age is less than 18, display "Sorry, you must be at least 18 years old."
If the age is 18 or older and the country is "USA", display "Welcome! Enjoy your stay in the USA."
If the age is 18 or older and the country is "UK", display "Welcome! Enjoy your stay in the UK."
If the age is 18 or older and the country is neither "USA" nor "UK", display "Welcome! Enjoy your stay."
  1. Question: Write a JavaScript program that prompts the user to enter a sentence. The program should perform the following operations:
Use the toLowerCase function to convert the sentence to lowercase.
Use the replace function to replace all spaces with dashes ("-") in the modified sentence.
Use the slice function to extract a substring from the 2nd to the 6th character (inclusive) of the modified and replaced sentence.
Use the startsWith function to check if the extracted substring starts with the letter "a".
Display the result of the check using an alert box.
  1. Question: Write a JavaScript function called calculateArea that takes the length and width of a rectangle as parameters and returns the area of the rectangle. The formula for calculating the area is length * width.

  2. Write a JavaScript function which calculate sum of 4 numbers. If sum of 4 numbers is greater than 100 then return 1 else return 2.