I want to make a website that can calculate the numbers that the user enters in the text field. Below, I am trying to store the users input in a variable and then return it to the console, but this does not seem to work. It is supposed to take in more calculations down the line, but I thought I would keep it simple at first. What have i forgotten?
PS: I'm currently still learning JavaScript, so don't roast me too hard :)
Thanks!
Best Mikkel
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="/JavaScript/culjo.js" defer></script>
<title>Culjo</title>
</head>
<body>
<h1>Culjo</h1>
<input id="inputOne" type="text">
<input id="inputtwo" type="text">
<input id="result" type="number">
<script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-
QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</body>
</html>
Javascript
function calculate() {
var inputOne = document.getElementById("inputOne")
var inputTwo = document.getElementById("inputTwo")
result = inputOne+inputTwo + inputTwo
return result
}
calculate()
parseInt()orparseFloat()the text box values otherwise they will be strings and will just concatenate instead of add.value(to get the value entered in the textbox) - eginputOne.value. And finally, you don't do anything with the result