<< Back

Exercise 1.1 - Buttons and Inputs

c) Calculate the sum

This is the console. All output created with writeLog() is shown here.

Please type a number in each input field and press "Add". I will print the sum of both to the console.


script.js

This is the JavaScript code behind the above application.

/* global writeLog, getInput */
log("Solution for exercise 1.1 c)");
function add() {
// Get the values from both input fields
var numberA = getInput("theNumberA");
var numberB = getInput("theNumberB");
writeLog("I will perform this calculation: " + numberA + " + " + numberB);
var sum = parseFloat(numberA) + parseFloat(numberB);
writeLog("The result is: " + sum);
}