< script type = "text/javascript" >
function myFunction() {
var n1 = document.getElementById("form-control1").innerHTML;
var n2 = document.getElementById("form-control2").innerHTML;
return Math.max(n1, n2);
};
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>JavaScript Challenge</title>
</head>
<body>
<!-- user interface -->
First number
<input type="text" id="form-control1" placeholder="your first number">Second number
<input type="text" id="form-control2" placeholder="your second number">
<br>
<br>
<button onclick="myFunction()">Calculate</button>
</script>
</body>
</html>
I would like the user input value to be assigned on the variable n1 and n2. After that when the button is clicked the variable with the max value is shown up on the webpage. but at the moment the value does not seem to be stored as it says undefined. what can i do? any help Thanks in advance
Aucun commentaire:
Enregistrer un commentaire