Question

In: Computer Science

In javascript, make a program that takes in a positive integer (entered on a textbox and...

In javascript, make a program that takes in a positive integer (entered on a textbox and submitted by clicking a button). Then, it displays the sum of all the integers between that number and zero.


<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
function add(n)
{
   /*This function MUST USE RECURSION to do the sum of the numbers.*/
}
function check()
{
   /*This function takes the input entered and checks if it's an integer. If it's not a number, it should say it's not. If it is, it calls the other function, and after the sum is returned by the other function, it is displayed.*/
}
</script>
</head>
<body>
<input type="text" name="numbers" id="numbers">
<input type="button" name="button" value="click" onclick="add();">
<p id="result"> </p>
</body></html>

Hint: use isNaN() and parseInt() functions.

Solutions

Expert Solution

Solution)

Explanation:I have completed the code have also shown the output, please find the images attached with the answer.Please upvote if you liked my answer and comment if you need any modification or explanation

<html>

<head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <script>

        function add(n) {

            if (n < 1) return 0;

            return n + add(n - 1);

        }

        function check() {

            var x = parseInt(document.getElementById("numbers").value);

            if (isNaN(x))

                document.getElementById('result').innerHTML = "It's not a number";

            else

                document.getElementById('result').innerHTML = add(x);

        }

    </script>

</head>

<body>

    <input type="text" name="numbers" id="numbers">

    <input type="button" name="button" value="click" onclick="check();">

    <p id="result"> </p>

</body>

</html>

Outputs:


Related Solutions

Write a program that takes in a positive integer as input, and outputs a string of...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the output is: 011 6 in binary is...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
Create a program that will calculate the factorial of any user entered integer. For any positive integer, the factorial is given as
Create a program that will calculate the factorial of any user entered integer. For any positive integer, the factorial is given as: n! = n·(n-1)·(n-2)·.……·3·2·1. The factorial of 0 is 1. If a number is negative, factorial does not exist and this program should display error message. Sample output dialogues should look like these:  Enter an integer: -5 ERROR!!! Tactorial of a negative number doesn't exist  Enter an integer: 10  Factorial = 3628800
6.28 LAB: Convert to binary - functions Write a program that takes in a positive integer...
6.28 LAB: Convert to binary - functions Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second...
Make a program that lets the user enter a positive or negative integer as many times...
Make a program that lets the user enter a positive or negative integer as many times as they want. java //import statement //class header //Begin class scope //Method header for main. //Begin method scope. //Declare input object for Scanner. //Declare variable called entry initialized to zero. //Declare variable called response initialized to blank space. //Prompt "Do you want to enter an integer? Y or N: " //Store value in correct variable.   //while header that tests uppercase in response //Begin scope...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:
USE Coral Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:As long as x is greater than 0    Output x % 2 (remainder is either 0 or 1)    x = x / 2Note: The above algorithm outputs the 0's and 1's in reverse order.Ex: If the input is 6, the output is:011(6 in binary is 110; the algorithm outputs the bits in reverse).
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:
In Java  Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:As long as x is greater than 0    Output x % 2 (remainder is either 0 or 1)    x = x / 2Note: The above algorithm outputs the 0's and 1's in reverse order.Ex: If the input is:6the output is:0116 in binary is 110; the algorithm outputs the bits in reverse.
[C] Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:
6.19 LAB: Convert to binary - functionsWrite a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:As long as x is greater than 0    Output x % 2 (remainder is either 0 or 1)    x = x / 2Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string.Ex: If the input is:6the output is:110Your program must define and call the following two functions. The IntegerToReverseBinary function...
(Python) Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:
In Python8.21 Program: Convert to binary. Sections 2.7, 3.8, 5.2. Functions.Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:As long as x is greater than 0    Output x % 2 (remainder is either 0 or 1)    x = x // 2Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string.Your program must define and call the following two functions. The function integer_to_reverse_binary() should return...
a program that takes an integer and outputs the resulting factorial number.
assembly x86 language program a program that takes an integer and outputs the resulting factorial number. 
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT