Posts

Showing posts with the label calculator

JavaScript calculator writes wrong number

JavaScript calculator writes wrong number I have a small error in this code, please help me. <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <input type="text" id="price"> <button onclick="calc()">GO</button> <h1 id="show"></h1> <script type="text/javascript"> function calc() { "use strict"; var price = document.getElementById('price').value; var res = (price / 100 * 5 + 20) + price; var show = document.getElementById('show').value = Math.floor(res); } </script> </b...