Hello, developers. I'm going to make a conditional statement and implement it.
if (b!==number) { alert('Number only allowed')} else {a*b}
a="What I typed in advance and am currently printing on the screen"
b= Like the code below, I designate it as the number value that the user enters in the text I made I want to, but how should I designate this?
<input type="text" name="user input value" value="number value entered by the user">
There are so many ways. Here's an example.
let inputValue = document.querySelector('input').value;
console.log(inputValue);
It's really hard to know how to enter the value of b.
var number = document.getElementById("number");
var result = document.getElementById("multiply");
var btn = document.getElementById("btn");
var numberValue = 0;
var preNumber = 10; // Pre-populated number
function multiply(){
if (typeof numberValue !== "number") {
alert('Only numbers are allowed.');
} } else {
var multiplyTwo = preNumber * numberValue;
}
result.innerHTML = multiplyTwo;
}
function readNumber(){
numberValue = parseInt(number.value);
}
number.addEventListener("keypress", readNumber);
btn.addEventListener("click", multiply)
;
html file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Page Title</title>
</head>
<body>
<input type="text" name="user input value" id="number" value="> // value is not pre-populated.
<button id="btn">Submit</button>
<p id='multiply'></p>
<script src="hashcode3.js"></script>
</body>
</html>
© 2024 OneMinuteCode. All rights reserved.