Question

I need help with a javascript assignment: Write a program called sum_number.js, that calculates the sum...

I need help with a javascript assignment:

Write a program called sum_number.js, that calculates the sum of the numbers contained in a string and displays the result. Use a string containing “2155” as your input value. For example, given the input , let num = “22”, I would sum 2 + 2 for a result of 4. The power is the amps at a given hour times the voltage at the same hour. Calculate the average power consumed for the day and display it at the end. i.e

0 0
Add a comment Improve this question Transcribed image text
Answer #1

<!DOCTYPE html>
<html>
<body>

Enter Number: <input type="text" id="num" name="txt"
onchange="myFunction(this.value)">

<script>
function myFunction(val) {
sum=0,n=0;
num=parseInt(val);
while(num > 0)
{
n = num % 10;
sum = sum + n;
num = num / 10;
}
alert(Math.floor(sum));
}
</script>

</body>
</html>

Add a comment
Know the answer?
Add Answer to:
I need help with a javascript assignment: Write a program called sum_number.js, that calculates the sum...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program using a function called sum that calculates the following summation: p=2+5 F...

    Write a C++ program using a function called sum that calculates the following summation: p=2+5 F = i2 + 5 i=1 Where n is provided by the user in the main function. The function calculates the sum and return it to the main function to display it.

  • I need help with this C++ assignment. Create a program which will implement the sum of...

    I need help with this C++ assignment. Create a program which will implement the sum of the numbers between 1 and n where n is an integer. When completed, the program will allow the user to input a positive integer (n) then the program will add all numbers between 1 and n (including n) and output the sum. For example, if the user enters 8 then the program will sum the numbers 1 through 8 and will output the sum....

  • Hi everyone! I need help on my Java assignment. I need to create a method that...

    Hi everyone! I need help on my Java assignment. I need to create a method that is called sumIt that will sum two values and will return the value.It should also invoke cubeIt from the sum of the two values. I need to change the currecnt program that I have to make it input two values from the console. The method has to be called sumIt and will return to the sum that will produce the cube of the sum...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • JavaScript Just use javascript, dont include HTML Follow the instructions bellow for a good rate Create...

    JavaScript Just use javascript, dont include HTML Follow the instructions bellow for a good rate Create a program that will display the result of three functions: a) sum the elements from the Fibonacci sequence b) divide them by randomly generated number c) calculate factorial from the rounded result of previous operation Functions should be stored in one, separate file. The main program should run from the app.js that is provided bellow, the other file should be called module.js that includes...

  • I need to write a C++ program that reads two integers from a data filed called...

    I need to write a C++ program that reads two integers from a data filed called "integers.dat" The first integer should be low and the other one high. The program should loop through all integers between the low and high values and include the low and high integers and then display Display the integers in the file Displays the number of integers divisible by 5 OR 6, but not both. Displays the sum of the integers from condition 2 as...

  • Need help with these scenarios Question 1 Write a JavaScript program to get the volume of...

    Need help with these scenarios Question 1 Write a JavaScript program to get the volume of a Cylinder with four decimal places using object classes. Volume of a cylinder : V = πr2h where r is the radius and h is the height of the cylinder. Your solution must include an HTML and a JavaScript file, with a button to create the cylinder, inputs for the cylinder's radius and height and an output to show the cyclinder's volume. Your solution...

  • JavaScript expert, I need your help : My program doesn't work. I have the following program,...

    JavaScript expert, I need your help : My program doesn't work. I have the following program, it is simple web page: Create an object called person with name = John, age = 50. Then, access the object to display "John is 50 years old”. I have written some code here. Hint: Create an object with the var keyword, followed by a name and an "=" sign. Put the properties and values inside the {}; signs Note: Use getElementById() and innerHTML...

  • Write a calculator program using JavaScript in HTML in the same HTML file. (There will only...

    Write a calculator program using JavaScript in HTML in the same HTML file. (There will only be 1 HTML file containing everything that you use for this program.) *************JavaScript Functions should be written in the HTML <head> .............. </head> tag, **************** (Please be mindful of the formatting of the text of your program. Meaning that do not copy paste everything in a single line. Add clear comments for a better understanding of your program) as follows Assignment: create a form...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT