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>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: #f0f2f5;
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,0.1);
padding: 2rem;
width: 100%;
max-width: 400px;
}
h1 {
text-align: center;
margin-bottom: 1.5rem;
color: #1a1a1a;
font-size: 1.5rem;
}
.field {
margin-bottom: 1rem;
}
label {
display: block;
margin-bottom: 0.3rem;
font-weight: 600;
color: #333;
font-size: 0.9rem;
}
input[type="number"] {
width: 100%;
padding: 0.6rem 0.8rem;
border: 1px solid #ccc;
border-radius: 8px;
font-size: 1rem;
outline: none;
transition: border-color 0.2s;
}
input[type="number"]:focus {
border-color: #4a90d9;
}
button {
width: 100%;
padding: 0.75rem;
background: #4a90d9;
color: #fff;
border: none;
border-radius: 8px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: background 0.2s;
margin-top: 0.5rem;
}
button:hover {
background: #357abd;
}
.results {
margin-top: 1.5rem;
padding-top: 1rem;
border-top: 1px solid #eee;
}
.result-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.5rem 0;
}
.result-row .label {
color: #555;
font-size: 0.95rem;
}
.result-row .value {
font-weight: 700;
font-size: 1.1rem;
color: #1a1a1a;
}
</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" step="0.01">
</div>
<div class="field">
<label for="tip">Tip Percentage (%)</label>
<input type="number" id="tip" placeholder="20" step="0.1">
</div>
<div class="field">
<label for="people">Number of People</label>
<input type="number" id="people" placeholder="1" step="1" min="1">
</div>
<button id="calculate">Calculate</button>
<div class="results">
<div class="result-row">
<span class="label">Total</span>
<span class="value" id="total">$0.00</span>
</div>
<div class="result-row">
<span class="label">Per Person</span>
<span class="value" id="perPerson">$0.00</span>
</div>
</div>
</div>
<script>
document.getElementById('calculate').addEventListener('click', function () {
var billRaw = document.getElementById('bill').value;
var tipRaw = document.getElementById('tip').value;
var peopleRaw = document.getElementById('people').value;
var bill = parseFloat(billRaw);
var tip = parseFloat(tipRaw);
// Treat empty or non-numeric as 0; clamp negatives to 0
if (isNaN(bill) || bill < 0) bill = 0;
if (isNaN(tip) || tip < 0) tip = 0;
// People: empty or < 1 treated as 1
var people = parseFloat(peopleRaw);
if (isNaN(people) || 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);
});
</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;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.card {
background: #ffffff;
border-radius: 16px;
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
padding: 2.5rem 2rem;
width: 100%;
max-width: 420px;
}
h1 {
font-size: 1.6rem;
text-align: center;
margin-bottom: 1.8rem;
color: #16213e;
}
label {
display: block;
font-size: 0.9rem;
font-weight: 600;
margin-bottom: 0.4rem;
color: #444;
}
input[type="number"] {
width: 100%;
padding: 0.7rem 0.9rem;
font-size: 1rem;
border: 2px solid #ddd;
border-radius: 8px;
outline: none;
transition: border-color 0.2s;
margin-bottom: 1.2rem;
}
input[type="number"]:focus {
border-color: #4361ee;
}
button#calculate {
width: 100%;
padding: 0.8rem;
font-size: 1.1rem;
font-weight: 700;
color: #fff;
background: #4361ee;
border: none;
border-radius: 8px;
cursor: pointer;
transition: background 0.2s;
margin-top: 0.4rem;
}
button#calculate:hover {
background: #3a56d4;
}
.results {
margin-top: 1.8rem;
padding-top: 1.4rem;
border-top: 2px solid #eee;
display: flex;
flex-direction: column;
gap: 0.8rem;
}
.results .row {
display: flex;
justify-content: space-between;
align-items: baseline;
}
.results .label {
font-size: 0.95rem;
color: #555;
}
.results .value {
font-size: 1.2rem;
font-weight: 700;
color: #16213e;
}
</style>
</head>
<body>
<div class="card">
<h1>Tip Calculator</h1>
<label for="bill">Bill Amount</label>
<input type="number" id="bill" placeholder="0.00" min="0" step="any">
<label for="tip">Tip Percentage</label>
<input type="number" id="tip" placeholder="20" min="0" step="any">
<label for="people">Number of People</label>
<input type="number" id="people" placeholder="1" min="1" step="1" value="1">
<button id="calculate">Calculate</button>
<div class="results">
<div class="row">
<span class="label">Total</span>
<span class="value" id="total">$0.00</span>
</div>
<div class="row">
<span class="label">Per Person</span>
<span class="value" id="perPerson">$0.00</span>
</div>
</div>
</div>
<script>
document.getElementById('calculate').addEventListener('click', function () {
var billRaw = document.getElementById('bill').value;
var tipRaw = document.getElementById('tip').value;
var peopleRaw = document.getElementById('people').value;
var bill = parseFloat(billRaw);
var tip = parseFloat(tipRaw);
// Treat empty or non-numeric as 0, clamp negatives to 0
if (isNaN(bill) || bill < 0) bill = 0;
if (isNaN(tip) || tip < 0) tip = 0;
var people = parseInt(peopleRaw, 10);
// Treat empty or < 1 as 1
if (isNaN(people) || 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);
});
</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;
}
.container {
background: #fff;
border-radius: 12px;
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
padding: 2rem;
width: 100%;
max-width: 420px;
}
h1 {
font-size: 1.5rem;
margin-bottom: 1.5rem;
text-align: center;
}
.field {
margin-bottom: 1rem;
}
label {
display: block;
font-size: 0.9rem;
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.2s;
}
input[type="number"]:focus {
border-color: #4299e1;
box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.2);
}
button {
width: 100%;
padding: 0.75rem;
font-size: 1rem;
font-weight: 600;
color: #fff;
background: #4299e1;
border: none;
border-radius: 6px;
cursor: pointer;
margin-top: 0.5rem;
transition: background 0.2s;
}
button:hover {
background: #3182ce;
}
button:active {
background: #2b6cb0;
}
.results {
margin-top: 1.5rem;
padding-top: 1.25rem;
border-top: 1px solid #e2e8f0;
}
.results p {
font-size: 1rem;
margin-bottom: 0.5rem;
}
.results .value {
font-weight: 700;
color: #2d3748;
}
</style>
</head>
<body>
<div class="container">
<h1>Tip Calculator</h1>
<div class="field">
<label for="bill">Bill Amount</label>
<input type="number" id="bill" placeholder="e.g. 100">
</div>
<div class="field">
<label for="tip">Tip Percentage</label>
<input type="number" id="tip" placeholder="e.g. 20">
</div>
<div class="field">
<label for="people">Number of People</label>
<input type="number" id="people" placeholder="e.g. 2" value="1">
</div>
<button id="calculate">Calculate</button>
<div class="results">
<p>Total: <span class="value" id="total"></span></p>
<p>Per Person: <span class="value" id="perPerson"></span></p>
</div>
</div>
<script>
document.getElementById('calculate').addEventListener('click', function () {
var rawBill = document.getElementById('bill').value;
var rawTip = document.getElementById('tip').value;
var rawPeople = document.getElementById('people').value;
var bill = parseFloat(rawBill);
if (isNaN(bill) || bill < 0) bill = 0;
var tip = parseFloat(rawTip);
if (isNaN(tip) || tip < 0) tip = 0;
var people = parseFloat(rawPeople);
if (isNaN(people) || 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);
});
</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>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: #f0f2f5;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.calculator {
background: #fff;
border-radius: 12px;
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
padding: 2rem;
width: 100%;
max-width: 400px;
}
h1 {
text-align: center;
font-size: 1.5rem;
color: #333;
margin-bottom: 1.5rem;
}
.field {
margin-bottom: 1.25rem;
}
label {
display: block;
font-size: 0.9rem;
font-weight: 600;
color: #555;
margin-bottom: 0.4rem;
}
input[type="number"] {
width: 100%;
padding: 0.6rem 0.75rem;
font-size: 1rem;
border: 1px solid #ccc;
border-radius: 6px;
outline: none;
transition: border-color 0.2s;
}
input[type="number"]:focus {
border-color: #4a90d9;
}
button {
width: 100%;
padding: 0.75rem;
font-size: 1rem;
font-weight: 600;
color: #fff;
background: #4a90d9;
border: none;
border-radius: 6px;
cursor: pointer;
transition: background 0.2s;
}
button:hover {
background: #357abd;
}
.results {
margin-top: 1.5rem;
padding-top: 1.25rem;
border-top: 1px solid #e0e0e0;
}
.result-row {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 0.5rem;
}
.result-label {
font-size: 0.95rem;
color: #555;
}
.result-value {
font-size: 1.1rem;
font-weight: 700;
color: #333;
}
</style>
</head>
<body>
<div class="calculator">
<h1>Tip Calculator</h1>
<div class="field">
<label for="bill">Bill Amount</label>
<input type="number" id="bill" placeholder="0.00" step="any">
</div>
<div class="field">
<label for="tip">Tip Percentage</label>
<input type="number" id="tip" placeholder="20" step="any">
</div>
<div class="field">
<label for="people">Number of People</label>
<input type="number" id="people" placeholder="1" step="any" min="1">
</div>
<button id="calculate">Calculate</button>
<div class="results">
<div class="result-row">
<span class="result-label">Total</span>
<span class="result-value" id="total">$0.00</span>
</div>
<div class="result-row">
<span class="result-label">Per Person</span>
<span class="result-value" id="perPerson">$0.00</span>
</div>
</div>
</div>
<script>
function clamp(value, min) {
if (typeof value !== "number" || isNaN(value)) return min;
return Math.max(value, min);
}
function parseBillOrTip(raw) {
var str = String(raw).trim();
if (str === "") return 0;
var num = parseFloat(str);
if (isNaN(num)) return 0;
return Math.max(num, 0);
}
function parsePeople(raw) {
var str = String(raw).trim();
if (str === "") return 1;
var num = parseInt(str, 10);
if (isNaN(num) || num < 1) return 1;
return num;
}
document.getElementById("calculate").addEventListener("click", function () {
var bill = parseBillOrTip(document.getElementById("bill").value);
var tipPercent = parseBillOrTip(document.getElementById("tip").value);
var people = parsePeople(document.getElementById("people").value);
var total = bill + bill * (tipPercent / 100);
var perPerson = total / people;
document.getElementById("total").textContent = "$" + total.toFixed(2);
document.getElementById("perPerson").textContent = "$" + perPerson.toFixed(2);
});
</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, "Segoe UI", 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,0.1);
padding: 2rem;
max-width: 420px;
width: 100%;
}
h1 {
font-size: 1.5rem;
text-align: center;
margin-bottom: 1.5rem;
color: #2d3748;
}
.field {
margin-bottom: 1rem;
}
label {
display: block;
font-size: 0.875rem;
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.2s;
}
input[type="number"]:focus {
border-color: #4299e1;
box-shadow: 0 0 0 3px rgba(66,153,225,0.15);
}
button {
width: 100%;
padding: 0.7rem;
font-size: 1rem;
font-weight: 600;
color: #fff;
background: #4299e1;
border: none;
border-radius: 6px;
cursor: pointer;
transition: background 0.2s;
margin-top: 0.5rem;
}
button:hover { background: #3182ce; }
button:active { background: #2b6cb0; }
.results {
margin-top: 1.5rem;
padding-top: 1.5rem;
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.75rem;
}
.result-label {
font-size: 0.9rem;
color: #718096;
}
.result-value {
font-size: 1.2rem;
font-weight: 700;
color: #2d3748;
}
.result-value.total {
font-size: 1.5rem;
color: #2b6cb0;
}
</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" step="any">
</div>
<div class="field">
<label for="tip">Tip Percentage</label>
<input type="number" id="tip" placeholder="20" step="any">
</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 (bill + tip)</span>
<span class="result-value total" 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 getBill() {
const raw = document.getElementById("bill").value.trim();
if (raw === "") return 0;
const val = parseFloat(raw);
if (isNaN(val) || val < 0) return 0;
return val;
}
function getTip() {
const raw = document.getElementById("tip").value.trim();
if (raw === "") return 0;
const val = parseFloat(raw);
if (isNaN(val) || val < 0) return 0;
return val;
}
function getPeople() {
const raw = document.getElementById("people").value.trim();
if (raw === "") return 1;
const val = parseFloat(raw);
if (isNaN(val) || val < 1) return 1;
return val;
}
function formatMoney(amount) {
return "$" + amount.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
document.getElementById("calculate").addEventListener("click", function () {
const bill = getBill();
const tip = getTip();
const people = getPeople();
const total = bill + bill * (tip / 100);
const perPerson = total / people;
document.getElementById("total").textContent = formatMoney(total);
document.getElementById("perPerson").textContent = formatMoney(perPerson);
document.getElementById("results").classList.add("visible");
});
</script>
</body>
</html>