inches centimetres calculator
custom.js
'use strict'const inputInches = document.getElementById('inches')const btn = document.getElementById('calc')const total = document.getElementById('total')function convertToCentimetres(inches) {const result = inches / .39370079return result}btn.addEventListener('click', () => {let centimetres = convertToCentimetres(inputInches.value)centimetres = Math.round(centimetres * 10) / 10total.innerHTML = `${centimetres} cm`})
index.html
<!DOCTYPE html><html><head><meta charset="utf-8"><title>JavaScript Convert Inches Calculator</title><meta name="robots" content="noindex, nofollow"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="styles.css"></head><body><header><h1>JavaScript Inches to Centimetres Calculator</h1></header><div class="wrapper"><div class="container"><div id="calculator"><table><tr><td>Inches:</td><td><input id="inches" type="text"></td></tr><tr><td>Total:</td><td id="total"></td></tr></table><button id="calc">Calculate</button></div><!-- .calculator --></div><!-- .container--></div><!-- .wrapper--><footer><small><a href="https://opensource.org/licenses/MIT">MIT</a></small></footer><script src="custom.js"></script></body></html>
styles.css
body {background: #eeeeee;font-size: 16px;font-family: "Trebuchet MS", Helvetica, sans-serif;margin: 0;}a {color: crimson;text-decoration: none;}a:hover {color: red;}/* Layout------------------------------------------*/header,.container,footer {margin: 0 auto;width: 88%;max-width: 1080px;}.wrapper {padding: 1em 0;background: #ffffff;}/* Table------------------------------------------*/td:first-child {text-align: right;}td {padding: .5em 0 .5em .7em;}#calculator {max-width: 266px;display: flex;flex-direction: column;align-items: flex-end;}input {font-size: 1em;background: linear-gradient(#eeeeee, #ffffff);border-top: 2px solid #cccccc;border-left: 2px solid #cccccc;border-bottom: 2px solid #eeeeee;border-bottom: 2px solid #eeeeee;padding: .5em;}button {font-size: 1em;border: none;background: linear-gradient(#ffffff, #eeeeee);outline: 0;padding: .5em 1em;border-radius: 15px;text-shadow: 1px 1px 3px rgba(198, 198, 198, 0.9);border: 2px solid #eeeeee;}button:hover {background: linear-gradient(#eeeeee, #ffffff);}