JavaScript Exercises

JavaScript Exercises

Repository of Javascript exercises that I have collected & created with the intention of adding exercises for beginners to intermediate level to help newcomers to the Javascript language.

The exercises are in no specific order and they intend to provide a variety and engaging challenges for newcomers.


⫚ Exercise 1

Write a JavaScript program to display the current day and time in the following format:

Today is Monday, the current time is 10 PM : 30m : 38s.

⤓ Show solution

⫚ Exercise 2

Write a JavaScript program to rotate the string 'jsIsAwesome', by periodically removing one letter from the end of the string and attaching it to the front. (right to left)

⤓ Show solution

⫚ Exercise 3

Write a JavaScript program where the program takes a random integer between 1 to 10, the user is then prompted to guess the number picked.
If the user input matches with guess number, the program will display a message "Great, you guessed it" otherwise display a message "Better luck next time".

⤓ Show solution

⫚ Exercise 4

Write a JavaScript program to display the days left until next Christmas in the following format:

Santa will deliver your presents in 89 days!

⤓ Show solution

⫚ Exercise 5

Write a JavaScript program to convert miles from a user input into kilometers, knowing that:

1mile = 1.60934km

⤓ Show solution

⫚ Exercise 6

Write a JavaScript program to check whether a given positive number is a multiple of 2 or a multiple of 6

⤓ Show solution

⫚ Exercise 7

Write a JavaScript program to find out from two different given integer values which is closest to 100:

let int1 = 76;
let int2 = 123;

⤓ Show solution

⫚ Exercise 8

Write a JavaScript program to capitalize the first letter of each word of the string:

let str = "Learning javascript can be a lot of fun!";

⤓ Show solution

⫚ Exercise 9

Write a JavaScript program to extract the first half of a given string of even length.

let str = "Jon has travelled the world, but his favorite country is Japan.";

⤓ Show solution

⫚ Exercise 10

Write a JavaScript program to reverse a number given number:

let int = 98341;

⤓ Show solution