July 15, 2024

JavaScript Numbers


This question again tests your knowledge of strings, but also it requires you to manipulate numbers.

Write JavaScript code that prompts the user to enter a number, via a dialogue box, and output the cube of this number, with a suitable message, in a browser. All input is assumed to be valid and no rounding of the result is required.

Link to answer.


The next question again requires you to manipulate numbers and strings; it will also require some iteration.

Write JavaScript that will accept any number from a user and subsequently output in a browser five lines showing addition to that number in multiples of 2, similar to the output below. Assume for the following illustration that the user entered 10. No error checking is required.

10 plus 2 equals 12
10 plus 4 equals 14
10 plus 6 equals 16
10 plus 8 equals 18
10 plus 10 equals 20

Link to answer.


This question is similar to Q2, but it will require some knowledge of a built in JavaScript library.

Write JavaScript code that prompts the user to input two successive numbers, via dialogue boxes. Your code should divide the first number by the second. Furthermore, the result should be rounded to the nearest integer value and output, with a suitable message, to a browser.

Link to answer.


Next page » Boolean conditions

Previous page « JavaScript strings








Up to top of page