Write a JavaScript program to calculate sum of 1 to n numbers

 


Code:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Practical-14</title>
</head>

<body>
    <script>

        var num = prompt("Enter the number ");
        var sum = 0;
        for (let i = 0i <= numi++) {
            sum = sum + i;

        }
        alert(`Sum of the 1 to ${num} numbers is :` + sum);

        
    </script>
</body>

</html>

Output:




Comments

Popular posts from this blog

Write A Program To Print Hello World Using Lex

Create a Student registration form using following tags form,input,textarea,button,select,optio. The registration form must consist of following information: first name,Middle name,last name, gender(use radio button),address,phone no,email id,hobbies(use checkbox),city,state,country,collage name (use dropdown menu).