I have been given a task to create a calculator by tomorrow using Javascript. Unfortunately, I am currently taking a distance course and Javascript has just been introduced in this assignment. While I am familiar with HTML and CSS, Javascript is something that I find really challenging.
Although I have started working on the code for the calculator, I am stuck because I cannot seem to find any relevant resources online that explain how to create a similar calculator or provide a simple explanation of Javascript. The calculator should not feature a submit button and its design is not important, but it needs to include two text fields.
function Calculate() {
var number1 = document.getElementById("number1").value;
var number2 = document.getElementById("number2").value;
number1_parsed = parseInt(number1);
number2_parsed = parseInt(number2);
if (number1_parsed) {} else
alert("Wrong characters");
return false;
} {
sum = number1_parsed + number2_parsed;
alert("Sum: " + sum);
}
<div id="calculator">
<h1> Calculator </h1>
<form name="kalkylator">
<input type="text" name="number1" id="number1" size="10" />
<input type="text" name="number2" id="number2" size="10" />
<input type="button" onclick="Calculate();" id="calculate" value="Result">
</form>
</div>