Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to take input n number in js

<!doctype html>
<html>
<head>
<script>
var i=0, n, sum=0, temp;
function fun()
{
  n = parseInt(document.getElementById("n").value);
  if(n)
  {
    document.getElementById("nVal").innerHTML = n;
    document.getElementById("tme").innerHTML = i+1;
    i++;
    temp = document.getElementById("one");
    temp.style.display = "none";
    temp = document.getElementById("two");
    temp.style.display = "block";
  }
}
function add()
{
  if(i==n)
  {
    temp = document.getElementById("two");
    temp.style.display = "none";
    temp = document.getElementById("three");
    temp.style.display = "block";
  }
  num = parseInt(document.getElementById("num").value);
  if(num)
  {
    sum = sum + num;
    document.getElementById("num").value = null;
    document.getElementById("tme").innerHTML = i+1;
    i++;
  }
}
function res()
{
  document.getElementById("result").value = sum;
}
</script>
</head>
<body>

<p id="one">Enter the Value of n: <input id="n">
<button onclick="fun()">ENTER</button></p>
<p id="two" style="display:none;">Enter <span id="nVal"></span> 
Numbers. Input No. <span id="tme"></span>: 
<input id="num"><button id="btn" onclick="add()">ENTER</button></p>
<p id="three" style="display:none;"><button onclick="res()">Add</button>
<input id="result"></p>

</body>
</html>
Comment

PREVIOUS NEXT
Code Example
Javascript :: post method in javascript 
Javascript :: jest cross origin localhost fobbiden 
Javascript :: like dislike node js 
Javascript :: Limit number of selected chekboxes 
Javascript :: how to use mdbreact in react js 
Javascript :: react this.state 
Javascript :: react multiple classname 
Javascript :: javascript select2 sortable 
Javascript :: Show Modal Dialog on Jetpack Compose 
Javascript :: JavaScript Sorting Arrays 
Javascript :: tailwind rn npm install 
Javascript :: discord js invite to channel 
Javascript :: on drop, drag, dragover event 
Javascript :: response intersepters for axios create 
Javascript :: get latlong of address in here map api javascript 
Javascript :: spotify uri 
Javascript :: vue method 
Javascript :: react use component 
Javascript :: react usestate hook 
Javascript :: js filter text 
Javascript :: react select remove the loading indicator 
Javascript :: json traversal in js 
Javascript :: if statemnt shorthand js without else 
Javascript :: create component in react 
Javascript :: Pass string using a function 
Javascript :: nesting express routes 
Javascript :: clear dict javascript 
Javascript :: javascript function return 
Javascript :: how to disable button if errors object isnt empty in react hook form 
Javascript :: Vue JS Syntax error: "Unexpected Token, expected 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =