Learn and practice JavaScript exercises

Practice 40 exercises in JavaScript

Learn and practice JavaScript by completing 40 exercises that explore different concepts and ideas. 

1. Use JavaScript to display pop up boxes (alert box, an alert box with line breaks, confirm box, prompt box)

2. Use JavaScript to call a function with an argument that returns a value.

3. Create a web page to demonstrate Java Script events.

4. Create a web page to demonstrate Java Script Exception handling.    

5. Write a JavaScript to accept your name and display it.

6. Write a JavaScript code to accept 10 numbers and check how many are +ive,  -ive, and zero.

7. Write a Program in JavaScript to find the factorial of a number between 1 to 10

8. Write a Program in  JavaScript to find the reverse of a digit.

9. Find whether the given number is a strong number or not.

10. Display all strong numbers in the given range.

11. Write a JavaScript code block, which greets a user with a message Welcome’. When a user leaves this page, the ‘Good-bye’ alert dialog box is displayed

12. When user selects a color from the drop-down list, change the background color of a div.

13. Demonstrate onblur and onfocus event handlers.

14. How to handle mouse events using JavaScript? Demonstrate using a example.

15. Write a script that displays the various Math & String Functions.   

16. Create a student registration form and show the form details. After clicking on submit button following validations must be performed:

    - Clear the previous value when a field is selected.

    - Display warning message when a field is left blank.

17. Create a web page that uses JavaScript to change the content of a paragraph.

18. How to add a bulleted list in a paragraph each time user clicks on a button.

19. Write a JavaScript function that finds both minimum and maximum from an array.

20. Create a JavaScript function to sort elements of an array.

21. Demonstrate the use of Arrow functions in JavaScript.

22. Find the area of a circle using an anonymous function in JavaScript.

23. Change the background color of a paragraph randomly using JavaScript.

24. Reverse a string : Write a function that takes a string as input and returns the string reversed.

25. Factorialize a number : Write a function that takes a number as input and returns the factorial of that number.

26. Check for palindrome : Write a function that takes a string as input and returns true if the string is a palindrome and false otherwise.

27. Find the longest word : Write a function that takes a string as input and returns the length of the longest word in the string.

28. Title case a sentence : Write a function that takes a string as input and returns the string with the first letter of each word capitalized.

29. Return largest numbers in arrays  : Write a function that takes an array of arrays of numbers as input and returns an array containing the largest number from each array.

30. Confirm the ending : Write a function that takes a string and a target substring as input and returns true if the string ends with the target substring, and false otherwise.

31. Repeat a string : Write a function that takes a string and a number as input and returns a new string that repeats the input string a given number of times.

32. Truncate a string : Write a function that takes a string and a number as input and returns a truncated version of the string, ending with an ellipsis (...) if the original string was longer than the given number.

33. Chunky monkey : Write a function that takes an array and a number as input and returns an array of arrays, where each sub-array contains a maximum of the given number of elements from the original array.

34. Speed Limit : If input/parameter is below speedlimit of 70 print => 'Good Safe Driving'. If input/parameter is above speedlimit of 70, every 5 kilometers is Penalty Point, print => 'Speed Limit Crossed by Penalty Point' + Point.

    If Driver gets more than 10 penalty points ie. above the speed limit 120, print => 'License Suspended'.

35. Write a function which checks given input/parameter

    - If input/parameter is divisible by 3 print => Fizz

    - If input/parameter is divisible by 5 print => Buzz

    - If input/parameter is divisible by 3 or 5 print => FizzBuzz

    - If input/parameter is NOT divisible by 3 or 5 print => given Input Number/Value

    - If input/parameter is other than Number/Value print => 'Nan - Not a Number! Please Input Number' 

36. Count-truthy-falsy-values! : Write a function which checks and count the truthy values from an array

    Falsy values in JavaScript are:

    - false

    - 0 (zero)

    - undefined

    - null

    - ''

    - NaN

37.  Write a function which checks and prints only the string type properties of an object.

38. Sum of multiples :Write a function which Calculate the sum of multiples of 3 and 5 for a given limit

39. Write a function which Calculate the sum of marks provided in an array, average it and also show Grade

    Grade criteria/mechanism is:

    - 0% to 70% => D Grade

    - 71% to 79% => C Grade

    - 81% to 89% => B Grade

    - 91% to 100% => A Grade

40. Write a function which show or print Prime Number upto provided range

    - Prime Numbers are those numbers whose factors are only `1` and `the number itself`

    - In simple language Prime Numbers are divisible by only `1` and `the number itself/himself`

    - Prime Numbers have only two factors: `1` and `the number itself/himself`

    - Example: 2, 3, 5, 7, 11, 13, 17, 19 and so on...

Comments