screenshot

CHECK PASS: required elements exist CHECK PASS: total: bill=100 tip=20 -> 120.00 CHECK PASS: total: bill=50 tip=10 -> 55.00 CHECK PASS: two-decimal formatting CHECK PASS: split: bill=100 tip=15 people=3 -> total 115.00, perPerson 38.33 CHECK PASS: people empty/<1 treated as 1 (perPerson == total) CHECK PASS: negative bill/tip clamped to 0 CHECK PASS: no uncaught JS errors on empty inputs score: 8/8 (100%)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tip Calculator</title>
<style>
*, *::before, *::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: system-ui, -apple-system, sans-serif;
background: #f0f2f5;
color: #1a1a2e;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 1rem;
}
.calculator {
background: #fff;
border-radius: 16px;
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
padding: 2.5rem 2rem;
width: 100%;
max-width: 420px;
}
h1 {
text-align: center;
font-size: 1.6rem;
margin-bottom: 1.8rem;
color: #16213e;
}
.field {
margin-bottom: 1.2rem;
}
label {
display: block;
font-size: 0.9rem;
font-weight: 600;
margin-bottom: 0.4rem;
color: #444;
}
input[type="number"] {
width: 100%;
padding: 0.65rem 0.8rem;
border: 2px solid #d1d5db;
border-radius: 8px;
font-size: 1rem;
transition: border-color 0.2s;
background: #fafbfc;
}
input[type="number"]:focus {
outline: none;
border-color: #4f46e5;
background: #fff;
}
button {
width: 100%;
padding: 0.75rem;
margin-top: 0.4rem;
border: none;
border-radius: 8px;
background: #4f46e5;
color: #fff;
font-size: 1.05rem;
font-weight: 600;
cursor: pointer;
transition: background 0.2s;
}
button:hover {
background: #4338ca;
}
button:active {
background: #3730a3;
}
.results {
margin-top: 1.8rem;
padding-top: 1.4rem;
border-top: 2px solid #eee;
display: none;
}
.results.visible {
display: block;
}
.result-row {
display: flex;
justify-content: space-between;
align-items: baseline;
padding: 0.5rem 0;
}
.result-row .label {
font-size: 0.95rem;
color: #555;
}
.result-row .value {
font-size: 1.25rem;
font-weight: 700;
color: #16213e;
}
.result-row.per-person {
border-top: 1px dashed #ddd;
margin-top: 0.3rem;
padding-top: 0.8rem;
}
.result-row.per-person .value {
color: #4f46e5;
}
</style>
</head>
<body>
<div class="calculator">
<h1>Tip Calculator</h1>
<div class="field">
<label for="bill">Bill Amount ($)</label>
<input type="number" id="bill" min="0" step="0.01" placeholder="0.00">
</div>
<div class="field">
<label for="tip">Tip Percentage (%)</label>
<input type="number" id="tip" min="0" step="1" placeholder="15">
</div>
<div class="field">
<label for="people">Number of People</label>
<input type="number" id="people" min="1" step="1" placeholder="1">
</div>
<button id="calculate">Calculate</button>
<div class="results" id="results">
<div class="result-row">
<span class="label">Total</span>
<span class="value" id="total"></span>
</div>
<div class="result-row per-person">
<span class="label">Per Person</span>
<span class="value" id="perPerson"></span>
</div>
</div>
</div>
<script>
(function () {
var billInput = document.getElementById('bill');
var tipInput = document.getElementById('tip');
var peopleInput = document.getElementById('people');
var calculateBtn = document.getElementById('calculate');
var totalEl = document.getElementById('total');
var perPersonEl = document.getElementById('perPerson');
var resultsDiv = document.getElementById('results');
function parseNonNegative(value) {
var num = parseFloat(value);
if (isNaN(num)) return 0;
return num < 0 ? 0 : num;
}
function parsePeople(value) {
var num = parseFloat(value);
if (isNaN(num) || num < 1) return 1;
return num;
}
function formatCurrency(num) {
return num.toFixed(2);
}
calculateBtn.addEventListener('click', function () {
var bill = parseNonNegative(billInput.value);
var tip = parseNonNegative(tipInput.value);
var people = parsePeople(peopleInput.value);
var total = bill + bill * (tip / 100);
var perPerson = total / people;
totalEl.textContent = '$' + formatCurrency(total);
perPersonEl.textContent = '$' + formatCurrency(perPerson);
resultsDiv.classList.add('visible');
});
})();
</script>
</body>
</html>
screenshot

CHECK PASS: required elements exist CHECK PASS: total: bill=100 tip=20 -> 120.00 CHECK PASS: total: bill=50 tip=10 -> 55.00 CHECK PASS: two-decimal formatting CHECK PASS: split: bill=100 tip=15 people=3 -> total 115.00, perPerson 38.33 CHECK PASS: people empty/<1 treated as 1 (perPerson == total) CHECK PASS: negative bill/tip clamped to 0 CHECK PASS: no uncaught JS errors on empty inputs score: 8/8 (100%)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tip Calculator</title>
<style>
*, *::before, *::after {
box-sizing: border-box;
}
body {
font-family: system-ui, -apple-system, sans-serif;
background: #f0f4f8;
color: #1a202c;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
}
.card {
background: #ffffff;
border-radius: 12px;
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
padding: 2rem 2.5rem;
width: 100%;
max-width: 380px;
}
h1 {
margin: 0 0 1.5rem;
font-size: 1.5rem;
text-align: center;
}
.field {
margin-bottom: 1.25rem;
}
label {
display: block;
font-size: 0.85rem;
font-weight: 600;
margin-bottom: 0.35rem;
color: #4a5568;
}
input[type="number"] {
width: 100%;
padding: 0.6rem 0.75rem;
font-size: 1rem;
border: 1px solid #cbd5e0;
border-radius: 6px;
outline: none;
transition: border-color 0.15s;
}
input[type="number"]:focus {
border-color: #4299e1;
box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.15);
}
button#calculate {
width: 100%;
padding: 0.7rem;
font-size: 1rem;
font-weight: 600;
color: #fff;
background: #4299e1;
border: none;
border-radius: 6px;
cursor: pointer;
margin-top: 0.5rem;
transition: background 0.15s;
}
button#calculate:hover {
background: #3182ce;
}
button#calculate:active {
background: #2b6cb0;
}
.results {
margin-top: 1.5rem;
padding-top: 1.25rem;
border-top: 1px solid #e2e8f0;
display: none;
}
.results.visible {
display: block;
}
.result-row {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 0.6rem;
}
.result-row:last-child {
margin-bottom: 0;
}
.result-label {
font-size: 0.9rem;
color: #4a5568;
}
.result-value {
font-size: 1.15rem;
font-weight: 700;
color: #1a202c;
}
.result-row.highlight .result-value {
color: #2f855a;
}
</style>
</head>
<body>
<div class="card">
<h1>Tip Calculator</h1>
<div class="field">
<label for="bill">Bill Amount</label>
<input type="number" id="bill" placeholder="0" step="any" min="0">
</div>
<div class="field">
<label for="tip">Tip Percentage</label>
<input type="number" id="tip" placeholder="0" step="any" min="0">
</div>
<div class="field">
<label for="people">Number of People</label>
<input type="number" id="people" placeholder="1" step="1" min="1">
</div>
<button type="button" id="calculate">Calculate</button>
<div class="results" id="results">
<div class="result-row highlight">
<span class="result-label">Total</span>
<span class="result-value" id="total"> </span>
</div>
<div class="result-row highlight">
<span class="result-label">Per Person</span>
<span class="result-value" id="perPerson"> </span>
</div>
</div>
</div>
<script>
(function () {
function clampedParse(inputId, floor) {
var raw = document.getElementById(inputId).value;
if (raw === '' || raw === '-') return floor;
var num = parseFloat(raw);
if (isNaN(num)) return floor;
return Math.max(num, floor);
}
document.getElementById('calculate').addEventListener('click', function () {
var bill = clampedParse('bill', 0);
var tip = clampedParse('tip', 0);
var people = clampedParse('people', 1);
if (people < 1) people = 1;
var total = bill + bill * (tip / 100);
var perPerson = total / people;
document.getElementById('total').textContent = '$' + total.toFixed(2);
document.getElementById('perPerson').textContent = '$' + perPerson.toFixed(2);
document.getElementById('results').classList.add('visible');
});
})();
</script>
</body>
</html>screenshot

CHECK PASS: required elements exist CHECK PASS: total: bill=100 tip=20 -> 120.00 CHECK PASS: total: bill=50 tip=10 -> 55.00 CHECK PASS: two-decimal formatting CHECK PASS: split: bill=100 tip=15 people=3 -> total 115.00, perPerson 38.33 CHECK PASS: people empty/<1 treated as 1 (perPerson == total) CHECK PASS: negative bill/tip clamped to 0 CHECK PASS: no uncaught JS errors on empty inputs score: 8/8 (100%)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tip Calculator</title>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: system-ui, -apple-system, sans-serif;
background: #f0f4f8;
color: #1a202c;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 1rem;
}
.card {
background: #fff;
border-radius: 12px;
box-shadow: 0 4px 24px rgba(0,0,0,.08);
padding: 2rem;
width: 100%;
max-width: 400px;
}
h1 {
font-size: 1.5rem;
margin-bottom: 1.5rem;
text-align: center;
}
.field { margin-bottom: 1rem; }
.field label {
display: block;
font-weight: 600;
font-size: .875rem;
margin-bottom: .35rem;
color: #4a5568;
}
.field input {
width: 100%;
padding: .6rem .75rem;
border: 1px solid #cbd5e0;
border-radius: 8px;
font-size: 1rem;
outline: none;
transition: border-color .15s;
}
.field input:focus { border-color: #4299e1; box-shadow: 0 0 0 3px rgba(66,153,225,.25); }
button {
width: 100%;
padding: .75rem;
margin-top: .5rem;
background: #3182ce;
color: #fff;
border: none;
border-radius: 8px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: background .15s;
}
button:hover { background: #2b6cb0; }
button:active { background: #2c5282; }
.results {
margin-top: 1.5rem;
padding-top: 1.25rem;
border-top: 1px solid #e2e8f0;
display: none;
}
.results.visible { display: block; }
.result-row {
display: flex;
justify-content: space-between;
padding: .5rem 0;
}
.result-row + .result-row { border-top: 1px dashed #e2e8f0; }
.result-label { color: #4a5568; }
.result-value { font-weight: 700; font-size: 1.125rem; color: #2d3748; }
</style>
</head>
<body>
<div class="card">
<h1>Tip Calculator</h1>
<div class="field">
<label for="bill">Bill Amount</label>
<input type="number" id="bill" placeholder="0.00" min="0" step="0.01">
</div>
<div class="field">
<label for="tip">Tip Percentage</label>
<input type="number" id="tip" placeholder="20" min="0" step="1">
</div>
<div class="field">
<label for="people">Number of People</label>
<input type="number" id="people" placeholder="1" min="1" step="1">
</div>
<button id="calculate">Calculate</button>
<div class="results" id="results">
<div class="result-row">
<span class="result-label">Total</span>
<span class="result-value" id="total"></span>
</div>
<div class="result-row">
<span class="result-label">Per Person</span>
<span class="result-value" id="perPerson"></span>
</div>
</div>
</div>
<script>
(function () {
function parseNonNeg(value) {
var n = Number(value);
if (isNaN(n) || n < 0) return 0;
return n;
}
function parsePeople(value) {
var n = Number(value);
if (isNaN(n) || n < 1) return 1;
return n;
}
function formatMoney(amount) {
return '$' + amount.toFixed(2);
}
document.getElementById('calculate').addEventListener('click', function () {
var bill = parseNonNeg(document.getElementById('bill').value);
var tip = parseNonNeg(document.getElementById('tip').value);
var people = parsePeople(document.getElementById('people').value);
var total = bill + bill * (tip / 100);
var perPerson = total / people;
document.getElementById('total').textContent = formatMoney(total);
document.getElementById('perPerson').textContent = formatMoney(perPerson);
var results = document.getElementById('results');
if (results) results.classList.add('visible');
});
})();
</script>
</body>
</html>
screenshot

CHECK PASS: required elements exist CHECK PASS: total: bill=100 tip=20 -> 120.00 CHECK PASS: total: bill=50 tip=10 -> 55.00 CHECK PASS: two-decimal formatting CHECK PASS: split: bill=100 tip=15 people=3 -> total 115.00, perPerson 38.33 CHECK PASS: people empty/<1 treated as 1 (perPerson == total) CHECK PASS: negative bill/tip clamped to 0 CHECK PASS: no uncaught JS errors on empty inputs score: 8/8 (100%)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tip Calculator</title>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: system-ui, -apple-system, sans-serif;
background: #f3f4f6;
color: #1f2937;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.card {
background: #fff;
border-radius: 12px;
box-shadow: 0 4px 24px rgba(0, 0, 0, .08);
padding: 2rem;
width: 100%;
max-width: 380px;
}
h1 { text-align: center; margin-bottom: 1.5rem; font-size: 1.5rem; }
fieldset { border: none; margin-bottom: 1rem; }
label {
display: block;
font-size: .875rem;
font-weight: 600;
margin-bottom: .25rem;
}
input[type="number"] {
width: 100%;
padding: .5rem .75rem;
border: 1px solid #d1d5db;
border-radius: 8px;
font-size: 1rem;
outline: none;
transition: border-color .2s;
}
input[type="number"]:focus { border-color: #6366f1; }
button {
width: 100%;
padding: .65rem;
background: #6366f1;
color: #fff;
border: none;
border-radius: 8px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: background .2s;
margin-top: .5rem;
}
button:hover { background: #4f46e5; }
.results {
margin-top: 1.25rem;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
text-align: center;
}
.result-box {
background: #f9fafb;
border-radius: 8px;
padding: .75rem;
}
.result-box small {
display: block;
font-size: .75rem;
color: #6b7280;
margin-bottom: .25rem;
}
.result-box span {
font-size: 1.25rem;
font-weight: 700;
color: #6366f1;
}
</style>
</head>
<body>
<main class="card">
<h1>Tip Calculator</h1>
<form onsubmit="return false;">
<fieldset>
<label for="bill">Bill Amount ($)</label>
<input type="number" id="bill" placeholder="0.00" step="any" min="0">
</fieldset>
<fieldset>
<label for="tip">Tip Percentage (%)</label>
<input type="number" id="tip" placeholder="15" step="any" min="0">
</fieldset>
<fieldset>
<label for="people">Number of People</label>
<input type="number" id="people" placeholder="1" step="1" min="1" value="1">
</fieldset>
<button id="calculate" type="button">Calculate</button>
</form>
<div class="results">
<div class="result-box">
<small>Total</small>
<span id="total">—</span>
</div>
<div class="result-box">
<small>Per Person</small>
<span id="perPerson">—</span>
</div>
</div>
</main>
<script>
function parseNonNeg(input) {
const val = parseFloat(input);
if (isNaN(val)) return 0;
return Math.max(0, val);
}
function parsePeople(input) {
const val = parseInt(input, 10);
if (isNaN(val) || val < 1) return 1;
return val;
}
function formatCurrency(n) {
return "$" + n.toFixed(2);
}
document.getElementById("calculate").addEventListener("click", function () {
var bill = parseNonNeg(document.getElementById("bill").value);
var tip = parseNonNeg(document.getElementById("tip").value);
var people = parsePeople(document.getElementById("people").value);
var total = bill + bill * (tip / 100);
var perPerson = total / people;
document.getElementById("total").textContent = formatCurrency(total);
document.getElementById("perPerson").textContent = formatCurrency(perPerson);
});
</script>
</body>
</html>
screenshot

CHECK PASS: required elements exist CHECK PASS: total: bill=100 tip=20 -> 120.00 CHECK PASS: total: bill=50 tip=10 -> 55.00 CHECK PASS: two-decimal formatting CHECK PASS: split: bill=100 tip=15 people=3 -> total 115.00, perPerson 38.33 CHECK PASS: people empty/<1 treated as 1 (perPerson == total) CHECK PASS: negative bill/tip clamped to 0 CHECK PASS: no uncaught JS errors on empty inputs score: 8/8 (100%)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tip Calculator</title>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: #f0f2f5;
color: #1a1a2e;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 1rem;
}
.card {
background: #fff;
border-radius: 16px;
box-shadow: 0 4px 24px rgba(0,0,0,.08);
padding: 2rem 2.5rem;
width: 100%;
max-width: 400px;
}
h1 {
text-align: center;
font-size: 1.5rem;
margin-bottom: 1.5rem;
color: #16213e;
}
.field { margin-bottom: 1.25rem; }
label {
display: block;
font-size: .85rem;
font-weight: 600;
margin-bottom: .35rem;
color: #555;
}
input[type="number"] {
width: 100%;
padding: .65rem .85rem;
font-size: 1rem;
border: 1.5px solid #d0d5dd;
border-radius: 8px;
outline: none;
transition: border-color .2s;
}
input[type="number"]:focus { border-color: #4361ee; }
button {
width: 100%;
padding: .75rem;
font-size: 1rem;
font-weight: 600;
color: #fff;
background: #4361ee;
border: none;
border-radius: 8px;
cursor: pointer;
transition: background .2s;
margin-top: .25rem;
}
button:hover { background: #3a56d4; }
.results {
margin-top: 1.5rem;
padding-top: 1.25rem;
border-top: 1px solid #e8e8e8;
display: none;
}
.results.visible { display: block; }
.row {
display: flex;
justify-content: space-between;
padding: .45rem 0;
font-size: 1rem;
}
.row .label { color: #555; }
.row .value { font-weight: 700; color: #16213e; }
</style>
</head>
<body>
<div class="card">
<h1>Tip Calculator</h1>
<div class="field">
<label for="bill">Bill Amount</label>
<input type="number" id="bill" min="0" step="0.01" placeholder="0.00">
</div>
<div class="field">
<label for="tip">Tip Percentage (%)</label>
<input type="number" id="tip" min="0" step="0.1" placeholder="20">
</div>
<div class="field">
<label for="people">Number of People</label>
<input type="number" id="people" min="1" step="1" placeholder="1">
</div>
<button id="calculate">Calculate</button>
<div class="results" id="results">
<div class="row">
<span class="label">Total:</span>
<span class="value" id="total"></span>
</div>
<div class="row">
<span class="label">Per Person:</span>
<span class="value" id="perPerson"></span>
</div>
</div>
</div>
<script>
function parseClamp(value, fallback) {
var num = Number(value);
if (isNaN(num) || num < 0) return fallback;
return num;
}
document.getElementById('calculate').addEventListener('click', function () {
var bill = parseClamp(document.getElementById('bill').value, 0);
var tip = parseClamp(document.getElementById('tip').value, 0);
var people = parseClamp(document.getElementById('people').value, 1);
if (people < 1) people = 1;
var total = bill + bill * (tip / 100);
var perPerson = total / people;
document.getElementById('total').textContent = total.toFixed(2);
document.getElementById('perPerson').textContent = perPerson.toFixed(2);
document.getElementById('results').classList.add('visible');
});
</script>
</body>
</html>