Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Monday, January 16, 2023

Calculate total and percentage using JavaScript

 

Calculate total and percentage using JavaScript




In this article, we are going to know how to Calculate total and percentage using JavaScript where student names and marks of three subjects are input by the user. In this program, we are going to use prompt() to input data and calculate the total and percentage without using function and event.

Calculate total and percentage using JavaScript


Formula

total=subject1 + subject2 + subject3


Percentage = (Obtain marks/Total marks) X 100


Source Code:


Calculate total and percentage using JavaScript


Explanation:


In the above program, we use the prompt () function to input the students' names and marks for three subjects. We define the variable marks1, marks2, and marks3 respectively for three subject marks.

The parseFloat() function is used to convert the input data into a floating point number.

Now, it calculates the total marks by adding all three subjects and store in the variable total and calculates the percentage by dividing the total marks by 300 and multiplying by 100 and store in the variable per.

Finally, it displays the result by using the document.write() on the page.


Output:


Calculate total and percentage using JavaScript

Final words:

I hope you understood how to calculate total and percentage using JavaScript. In the next article, we are going to solve the same problem by using functions and buttons. If you have any suggestions, please feel me to write it the comment box.




No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages