Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.1 kB
1
Indexable
Never
<html>
<head>
	<title>Числа</title>
</head>
<body>
	<p>
		<span>СУММА: </span><span id="num_sum"></span>
	</p>
	
	<input type="number" name="1" id="num_1"><br>
	<input type="number" name="2" id="num_2"><br>
	<input type="number" name="3" id="num_3"><br>
	<input type="number" name="4" id="num_4"><br>
	<input type="number" name="5" id="num_5"><br>
</body>

<script>
	var input1 = document.getElementById('num_1');
	var input2 = document.getElementById('num_2');
	var input3 = document.getElementById('num_3');
	var input4 = document.getElementById('num_4');
	var input5 = document.getElementById('num_5');
	let inputs = [input1, input2, input3, input4, input5];
	
	var result_text = document.getElementById('num_sum');
	
	function showSum() {
		let summa = 0;
		inputs.forEach((input, index, array) => {
			if(input.value){
				summa += parseInt(input.value)
			}
		});
		
		result_text.innerHTML = summa;
	}

	input1.oninput = showSum;
	input2.oninput = showSum;
	input3.oninput = showSum;
	input4.oninput = showSum;
	input5.oninput = showSum;
</script>
</html>
Leave a Comment