Solution: Add two numbers
examples/js/add_numbers.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> <title>Add numbers</title> </head> <body> <input id="x"> <input id="y"> <button id="go">+</button> <div id="result"></div> <script src="add_numbers.js"></script> </body> </html>
examples/js/add_numbers.js
"use strict"; function add() { var x = Number(document.getElementById('x').value); var y = Number(document.getElementById('y').value); document.getElementById('result').innerHTML = x+y; return false; } document.getElementById('go').addEventListener('click', add);