gallery price calculator
custom.js
'use strict'const artistsPrice = document.getElementById('price')const galleryPercentage = document.getElementById('percent')const galleryCommission = document.getElementById('commission')const galleryTotal = document.getElementById('total')const btn = document.getElementById('calc')function commissionCalc(price, percent) {const total = price * (1 + ( percent / (1 - percent / 100) / 100))return total}btn.addEventListener('click', () => {const galleryPrice = commissionCalc(artistsPrice.value, galleryPercentage.value)const commission = Math.round((galleryPrice - artistsPrice.value) * 100) / 100galleryCommission.innerHTML = commission.toFixed(2)galleryTotal.innerHTML = galleryPrice.toFixed(2)})
index.html
<!DOCTYPE html><html><head><meta charset="utf-8"><title>JavaScript Gallery Price 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 Gallery Price Calculator</h1></header><div class="wrapper"><div class="container"><p>Formula: x * (1 + ( y / (1 - y / 100) / 100)), where x is the artists price and y is the gallery percentage.</p><div id="calculator"><table><tr><td>Artists Price: $</td><td><input id="price" type="text"></td></tr><tr><td>Gallery Commission: %</td><td><input id="percent" type="text"></td></tr><tr><td>Gallery Commission: $</td><td id="commission"></td></tr><tr><td>Gallery Total: $</td><td id="total"></td></tr></table><button id="calc">Calculate</button></div></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;}tr:last-child td:last-child {border-top: 2px solid black;}#calculator {max-width: 376px;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);}