What is JavaScript?JavaScript is a cross-platform, object-oriented scripting language. It is a small and lightweight language. Inside a host environment ( a web browser), JavaScript can be connected to the objects of its environment to provide programmatic control over them. Show JavaScript contains a standard library of objects, such as Array, Date, and Math, and a core set of language elements such as operators, control structures, and statements. Core JavaScript can be extended for a variety of purposes by supplementing it with additional objects. The best way we learn anything is by practice and exercise questions. We have started this section for those (beginner to intermediate) who are familiar with JavaScript. Hope, these exercises help you to improve your JavaScript coding skills. Currently following sections are available, we are working hard to add more exercises. Happy Coding! More to Come ! Popularity of Programming Language Worldwide, Sep 2022 compared to a year ago:Source : https://pypl.github.io/PYPL.html TIOBE Index for September 2022 Source : https://www.tiobe.com/tiobe-index/ Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page. Note : Since JavaScript is a loosely-typed, dynamic and expressive language, you may accomplish the same task in various ways. Therefore the ways (solution of the exercises) described here are not the only ways to do stuff. Rather, it would be great, if this helps you anyway to choose your own methods. [ Want to contribute to JavaScript exercises? Send your code (attached with a .zip file) to us at w3resource[at]yahoo[dot]com. Please avoid copyrighted materials.] JavaScript: Tips of the DayProperty (() => { let x = (y = 10); })(); console.log(typeof x); console.log(typeof y); let x = y = 10; is actually shorthand for: y = 10; let x = y; When we set y equal to 10, we actually add a property y to the global object (window in
browser, global in Node). In a browser, window.y is now equal to 10. Ref: https://bit.ly/323Y0P6 JavaScript basic [150 exercises with solution][An editor is available at the bottom of the page to write and execute the scripts.]1. Write a JavaScript program to display the current day and time in the following format. Go to the editor 2. Write a JavaScript program to print the contents of the current window. Go to the editor 3. Write a JavaScript program to get the current date. Go to the editor 4. Write a JavaScript program to find the area of a triangle where lengths of the three of its sides are 5, 6, 7. Go to the
editor 5. Write a JavaScript program to rotate the string 'w3resource' in right direction by periodically removing one letter from the end of the string and attaching it to the front. Go to the editor 6. Write a JavaScript program to determine whether a given year is a leap year in the Gregorian calendar. Go to the editor 7. Write a JavaScript program to find 1st January is being a Sunday between 2014 and 2050. Go to the editor 8. Write a JavaScript program where the program takes a random integer between 1 to 10, the user is then prompted to input a guess number. If the user input matches with guess number, the program will display a message "Good Work" otherwise display a message "Not matched". Go to the editor 9. Write a JavaScript program to calculate days left until next Christmas. Go to the
editor 10. Write a JavaScript program to calculate multiplication and division of two numbers (input from user). Go to the editor Click me to see the solution 11. Write a JavaScript program to convert temperatures to and from Celsius, Fahrenheit. Go to the editor 12. Write a JavaScript program to get the website URL (loading page). Go to the editor 13. Write a JavaScript exercise to create a variable using a user-defined name. Go to
the editor 14. Write a JavaScript exercise to get the extension of a filename. Go to the editor 15. Write a JavaScript program to get the difference between a given number and 13, if the number is greater than 13 return double the absolute difference. Go to the editor 16. Write a JavaScript program to compute the sum of the two given integers. If the two values are same, then returns triple their sum. Go to the editor 17. Write a JavaScript program to compute the absolute difference between a specified number and 19. Returns triple their absolute difference if the specified number is greater than 19. Go to the editor 18. Write a JavaScript program to check two given numbers and return true if one of the number is 50 or if their sum is 50. Go to the editor 19. Write a JavaScript program to check whether a given integer is within 20 of 100 or 400. Go to the editor 20. Write a JavaScript program to check from two given integers, whether one is positive and another one is negative. Go to the editor 21. Write a JavaScript program to create a new string adding "Py" in front of a given string. If the given string begins with "Py" then return the original string. Go to the editor 22. Write a JavaScript program to remove a character at the specified position of a given string and return the new string. Go to the editor 23. Write a JavaScript program to create a new string from a given string changing the position of first and last characters. The string length must be greater than or equal to 1. Go to the editor 24. Write a JavaScript program to create a new string from a given string with the first character of the given string added at the front and back. Go to the editor 25. Write a JavaScript program to check whether a given positive number is a multiple of 3 or a multiple of 7. Go to the editor 26. Write a JavaScript program to create a new string from a given string taking the last 3 characters and added at both the front and back. The string length must be 3 or more. Go to the editor 27. Write a JavaScript program to check whether a string starts with 'Java' and false otherwise. Go to the editor 28. Write a JavaScript program to check whether two given integer values are in the range 50..99 (inclusive). Return true if either of them are in the said range. Go to the editor 29. Write a JavaScript program to check whether three given integer values are in the range 50..99 (inclusive). Return true if one or more of them are in the said range. Go to the editor 30. Write a JavaScript program to check whether a string "Script" presents at 5th (index 4) position in a given string, if "Script" presents in the string return the string without "Script" otherwise return the original one. Go to the editor 31. Write a JavaScript program to find the largest of three given integers. Go to the
editor 32. Write a JavaScript program to find a value which is nearest to 100 from two different given integer values. Go to the editor 33. Write a JavaScript program to check whether two numbers are in range 40..60 or in the range 70..100 inclusive. Go to the editor 34. Write a JavaScript program to find the larger number from the two given positive integers, the two numbers are in the range 40..60 inclusive. Go to the editor 35. Write a program to check whether a specified character exists within the 2nd to 4th position in a given string. Go to the editor 36. Write a JavaScript program to check whether the last digit of the three given positive integers is same. Go to the editor 37. Write a JavaScript program to create new string with first 3 characters are in lower case from a given string. If the string length is less than 3 convert all the characters in upper case. Go to the editor 38. Write a JavaScript program to check the total marks of a student in various examinations. The student will get A+ grade if the total marks are in the range 89..100 inclusive, if the examination is "Final-exam." the student will get A+ grade and total marks must be greater than or equal to 90. Return true if the student get A+ grade
or false otherwise. Go to the editor 39. Write a JavaScript program to compute the sum of the two given integers, If the sum is in the range 50..80 return 65 other wise return 80. Go to the editor 40. Write a JavaScript program to check from two given integers whether one of them is 8 or their sum or difference is 8. Go to the editor 41. Write a JavaScript program to check three given numbers, if the three numbers are same return 30 otherwise return 20 and if two numbers are same return 40. Go to the editor 42. Write a JavaScript program to check whether three given numbers are increasing in strict mode or in soft mode. Go to the editor 43. Write a JavaScript program to check from three given numbers (non negative integers) that two or all of them have
the same rightmost digit. Go to the editor 44. Write a JavaScript program to check from three given integers that whether a number is greater than or equal to 20 and less than one of the others. Go to the editor 45. Write a JavaScript program to check two given integer values and return true if one of the number is 15 or if their sum or difference is 15. Go to the editor 46. Write a JavaScript program to check two given non-negative integers that whether one of the number (not both) is multiple of 7 or 11. Go to the editor 47. Write a JavaScript program to check whether a given number is presents in the range 40..10000. Go to the editor 48. Write a JavaScript program to reverse a given string. Go to the editor 49. Write a JavaScript program to replace every character in a given string with the character following it in the alphabet. Go to the editor 50. Write a JavaScript program to capitalize the first letter of each word of a given string. Go to the editor 51. Write a JavaScript program to convert a given number to hours and minutes. Go to
the editor 52. Write a JavaScript program to convert the letters of a given string in alphabetical order. Go to the editor 53. Write a JavaScript program to check whether the characters a and b are separated by exactly 3 places anywhere (at least once) in a given string. Go to the editor 54. Write a JavaScript program to count the number of vowels in a given string. Go to the editor 55. Write a JavaScript program to check whether a given string contains equal number of p's and t's. Go to the editor 56. Write a JavaScript program to divide
two positive numbers and return a string with properly formatted commas. Go to the editor 57. Write a JavaScript program to create a new string of specified copies (positive number) of a given string. Go to the editor 58. Write a JavaScript program to create a new string of 4 copies of the last 3 characters of a given original string. The length of the given string must be 3 and above. Go to the editor 59. Write a JavaScript program to extract the first half of a string of even length. Go to the editor 60. Write a JavaScript program to create a new string without the first and last character of a given string. Go to the editor 61. Write a JavaScript program to concatenate two strings except their first character. Go to the editor 62. Write a JavaScript program to move last three character to the start of a given string. The string length must be greater or equal to three. Go to the editor 63. Write a JavaScript program to create a string using the middle three characters of a given string of odd length. The string length must be greater or equal to three. Go to the editor 64. Write a JavaScript program to concatenate two strings and return the result. If the length of the strings are not same then remove the characters from the longer string. Go to the editor 65. Write a JavaScript program to test whether a string end with "Script". The string length must be greater or equal to 6. Go to the editor 66. Write a JavaScript program to display the city name if the string begins with "Los" or "New" otherwise return blank. Go to the editor 67. Write a JavaScript program to create a new string from a given string, removing the first and last characters of the string if the first or last character are 'P'. Return the original string if the
condition is not satisfied. Go to the editor 68. Write a JavaScript program to create a new string using the first and last n characters from a given sting. The string length must be greater or equal to n.
Go to the editor 69. Write a JavaScript program to compute the sum of three elements of a given array of integers of length 3. Go to the editor 70. Write a JavaScript program to rotate the elements left of a given array of integers of length 3. Go to the editor 71. Write a JavaScript program to check whether 1 appears in first or last position of a given array of integers. The array length must be greater or equal to 1. Go to the editor 72. Write a JavaScript program to check whether the first and last elements are equal of a given array of integers length 3. Go to the editor 73. Write a JavaScript program to reverse the elements of a given array of integers length 3. Go to the editor 74. Write a JavaScript program to find the larger value between the first or last and set all the other elements with that value. Display the new array. Go to the editor 75. Write a JavaScript program to create a new array taking the middle elements of the two arrays of integer and each length 3. Go to the editor 76. Write a JavaScript program to create a new array taking the first and last elements from a given array of integers and length must be greater or equal to 1. Go to the editor 77. Write a JavaScript program to test whether an array of integers of length 2 contains 1 or a 3. Go to the editor 78. Write a JavaScript program to test whether an array of integers of length 2 does not contain 1 or a 3. Go to the editor 79. Write a JavaScript program to test whether a given array of integers contains 30 and 40 twice. The array length should be 0, 1, or 2. Go to the editor 80. Write a JavaScript program to swap the first and last elements of a given array of integers. The array length should be at least 1. Go to the editor 81. Write a JavaScript program to add two digits of a given positive integer of length two. Go to the editor 82. Write a JavaScript to add two positive integers without carry. Go to the
editor 83. Write a JavaScript to find the longest string from a given array of strings. Go to the editor 84. Write a JavaScript to replace each character of a given string by the next one in the English alphabet. Go to the editor 85. Write a JavaScript code to divide a given array of positive integers into two parts. First element goes to first part, second element goes to second part, and third element goes to first part and so on. Now compute the sum of two parts and store into an array of size two. Go to the editor 86. Write a JavaScript program to find the types of a given angle. Go to the
editor
87. Write a JavaScript program to check whether two arrays of integers of same length are
similar or not. The arrays will be similar if one array can be obtained from another array by swapping at most one pair of elements. Go to the editor 88. Write a JavaScript program that takes two integers and a
divisor. If the given divisor divides both integers and it does not divide either, then two given integers are similar. Check whether two given integers are similar or not. Go to the editor 89. Write a
JavaScript program to check whether it is possible to replace $ in a given expression x $ y = z with one of the four signs +, -, * or / to obtain a correct expression. Go to the editor 90. Write a JavaScript program to find the kth greatest element of a given array of integers Go to the editor 91. Write a JavaScript program to find the maximum possible sum of some of its k consecutive numbers (numbers that follow each other in order.) of a given array of positive integers. Go to the editor 92. Write a JavaScript program to find the maximal difference between any two adjacent elements of a given array of integers. Go to the editor 93. Write a JavaScript program to find the maximal difference among all possible pairs of a given array of integers. Go to the editor 94. Write a JavaScript program to find the number which appears most in a given array of integers. Go to the editor 95. Write a JavaScript program to replace all the numbers with a specified number of a given array of integers. Go to the editor 96. Write a JavaScript program to compute the sum of absolute differences of consecutive numbers of a given array of integers. Go to the editor 97. Write a JavaScript program to find the shortest possible string which can create a string to make it a palindrome by adding characters to the end of it. Go to the editor 98. Write a JavaScript program to switch case of the minimum possible number of letters to make a given string written in the upper case or in the lower case. Go to the editor 99. Write a JavaScript program to check whether it is possible to rearrange characters of a given string in such way that it will become equal to another given string. Go to the editor 100. Write a JavaScript program to check whether there is at least one element which occurs in two given sorted arrays of integers. Go to the editor 101. Write a JavaScript program to check whether a given string contains only Latin letters and no two uppercase and no two lowercase letters are in adjacent positions. Go to the editor 102. Write a JavaScript program to find the number of inversions of a given array of integers. Go to the editor 103. Write a JavaScript program to find the maximal number from a given positive integer by deleting exactly one digit of the given number. Go to the editor 104. Write a JavaScript program to find two elements of the array such that their absolute difference is not greater than a given integer but is as close to the said integer. Go to the editor 105. Write a JavaScript program to find the number of times to replace a given number with the sum of its digits until it convert to a single digit number. Go to the editor 106. Write a JavaScript program to divide an integer by another integer as long as the result is an integer and return the result. Go to the editor 107. Write a JavaScript program to find the number of sorted pairs formed by its elements of a given array of integers such that one element in the pair is divisible by the other one. Go to the editor 108. Write a JavaScript program to create the dot products of two given 3D vectors. Go to the editor 109. Write a JavaScript program to sort an array of all prime numbers between 1 and a
given integer. Go to the editor 110. Write a JavaScript program to find the number of even values in sequence before the first occurrence of a given number. Go to the editor 111. Write a JavaScript program to check a number from three given numbers where two numbers are equal, find the third one. Go to the editor 112. Write a JavaScript program to find the number of trailing zeros in the decimal representation of the factorial of a given number. Go to the editor 113. Write a JavaScript program to calculate the sum of n + n/2 + n/4 + n/8 + .... where n is a positive integer and all divisions are integer. Go to the editor 114. Write a JavaScript program to check whether a given string represents a correct sentence or not. A string is considered correct sentence if it starts with the capital letter and ends with a full
stop (.). Go to the editor 115. Write a JavaScript program to check whether a matrix is a diagonal matrix or not. In linear algebra, a diagonal matrix is a matrix in which the entries outside the main diagonal
are all zero (the diagonal from the upper left to the lower right). Go to the editor 116. Write a
JavaScript program to find all the possible options to replace the hash in a string (Consists of digits and one hash (#)) with a digit to produce an integer divisible by 3. Go to the editor 117. Write a JavaScript program to check whether a given matrix is an identity matrix. Go to the editor 118. Write a JavaScript program to check whether a given number is in a given range. Go to the editor 119. Write a JavaScript program to check whether a given integer has an increasing digits sequence. Go to the editor 120. Write a JavaScript program to check whether a point lies strictly inside a given circle. Go to the editor 121. Write a JavaScript program to check whether a given matrix is lower triangular or not. Go to the editor 122. Write a JavaScript program to check whether a given array of integers represents either a strictly increasing or a strictly decreasing sequence. Go to the editor 123. Write a JavaScript program to find whether the members of a given array of integers is a permutation of numbers from 1 to a given integer. Go to the editor 124. Write a JavaScript program to create the value of NOR of two given booleans. Go to the editor 125.
Write a JavaScript program to find the longest string from a given array. Go to the editor 126. Write a JavaScript program to get the largest even number from an array of integers. Go to the editor 127. Write a JavaScript program to reverse the order of the bits in a given integer. Go to the editor 128. Write a JavaScript program to find the smallest round
number that is not less than a given value. Go to the editor 129.
Write a JavaScript program to find the smallest prime number strictly greater than a given number. Go to the editor 130. Write a JavaScript program to find the number of even digits in a given integer. Go to the editor 131. Write a JavaScript program to create an array of prefix sums of the given array. Go to the editor 132. Write a JavaScript program to find all distinct prime factors of a given integer. Go to the editor 133. Write a JavaScript program to check whether a given fraction is proper or not. Go to the editor 134. Write a JavaScript program to change the characters (lower case) in a string where a turns into z, b turns into y, c turns into x, ..., n turns into m, m turns into n, ..., z turns into a. Go to the editor 135. Write a JavaScript program to remove all characters from a given string that appear more than once. Go to the editor 136. Write a JavaScript program to replace the first digit in a string (should contains at least digit) with $ character. Go to the editor 137. Write a JavaScript program to test whether a given integer is greater than 15 return the given number, otherwise return 15. Go to the editor 138. Write a JavaScript program to reverse the bits of a given 16 bits unsigned short integer. Go to the editor 139. Write a JavaScript program to find the position of a rightmost round number in an array of integers. Returns 0 if there are no round number. Go to the editor 140. Write a JavaScript program to check whether all the digits in a given number are the same or
not. Go to the editor 141. Write a JavaScript program to find the number of elements which presents in both of the given arrays. Go to the editor 142. Write a JavaScript program to simplify a given absolute path for a file in Unix-style. Go to the editor 143. Write a JavaScript program to sort the strings of a given array of strings in the order of increasing lengths. Go to the editor 144. Write a JavaScript program to break an address of an url and put it's part into an array. Go to the editor 145. Write a JavaScript program to find the maximum integer n such that 1 + 2 + ... + n <= a given integer. Go to the editor 146. Write a JavaScript program to compute the sum of cubes of all integer from 1 to a given integer. Go to the editor 147. Write a JavaScript program to compute the sum of all digits that occur in a given string. Go to the editor 148. Write a JavaScript program to swap two halves of a given array of integers of even length. Go to the editor 149. Write a JavaScript program to change the capitalization of all letters in a given string. Go to the editor 150. Write a JavaScript program to swap pairs of adjacent digits of a given integer of even length. Go to the editor More to Come ! Live Demo * To run the code mouse over on Result panel and click on 'RERUN' button.* See the Pen javascript-common-editor by w3resource (@w3resource) on CodePen. Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page. |