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>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background-color: #f4f7f6;
}
.card {
background: white;
padding: 2rem;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
width: 100%;
max-width: 400px;
}
h1 {
margin-top: 0;
text-align: center;
color: #333;
}
.input-group {
margin-bottom: 1.5rem;
}
label {
display: block;
margin-bottom: 0.5rem;
font-weight: 600;
color: #666;
}
input {
width: 100%;
padding: 0.75rem;
border: 1px solid #ddd;
border-radius: 6px;
box-sizing: border-box;
font-size: 1rem;
}
button {
width: 100%;
padding: 0.75rem;
background-color: #007bff;
color: white;
border: none;
border-radius: 6px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: background-color 0.2s;
}
button:hover {
background-color: #0056b3;
}
.results {
margin-top: 2rem;
padding-top: 1.5rem;
border-top: 1px solid #eee;
}
.result-item {
display: flex;
justify-content: space-between;
margin-bottom: 1rem;
font-size: 1.1rem;
}
.result-value {
font-weight: bold;
color: #333;
}
</style>
</head>
<body>
<div class="card">
<h1>Tip Calculator</h1>
<div class="input-group">
<label for="bill">Bill Amount</label>
<input type="number" id="bill" placeholder="0.00" step="0.01">
</div>
<div class="input-group">
<label for="tip">Tip Percentage (%)</label>
<input type="number" id="tip" placeholder="15" step="1">
</div>
<div class="input-group">
<label for="people">Number of People</label>
<input type="number" id="people" placeholder="1" step="1">
</div>
<button id="calculate">Calculate</button>
<div class="results">
<div class="result-item">
<span>Total Bill:</span>
<span class="result-value" id="total">$0.00</span>
</div>
<div class="result-item">
<span>Each Person Pays:</span>
<span class="result-value" id="perPerson">$0.00</span>
</div>
</div>
</div>
<script>
document.getElementById('calculate').addEventListener('click', () => {
// Get input values
const billInput = document.getElementById('bill').value;
const tipInput = document.getElementById('tip').value;
const peopleInput = document.getElementById('people').value;
// Parsing and Clamping:
// Empty or non-numeric treated as 0. Negative treated as 0.
let bill = parseFloat(billInput);
if (isNaN(bill) || bill < 0) {
bill = 0;
}
let tipPercent = parseFloat(tipInput);
if (isNaN(tipPercent) || tipPercent < 0) {
tipPercent = 0;
}
// Parsing and Clamping:
// Empty or less than 1 treated as 1.
let people = parseInt(peopleInput, 10);
if (isNaN(people) || people < 1) {
people = 1;
}
// Calculations
const total = bill + (bill * (tipPercent / 100));
const perPerson = total / people;
// Formatting to exactly two decimal places
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>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background-color: #f4f7f6;
}
.calculator-card {
background: white;
padding: 2rem;
border-radius: 12px;
box-shadow: 0 10px 25px rgba(0,0,0,0.1);
width: 100%;
max-width: 400px;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 1.5rem;
}
.input-group {
margin-bottom: 1rem;
}
label {
display: block;
margin-bottom: 0.5rem;
color: #666;
font-size: 0.9rem;
}
input {
width: 100%;
padding: 0.8rem;
border: 1px solid #ddd;
border-radius: 6px;
box-sizing: border-box;
font-size: 1rem;
}
button {
width: 100%;
padding: 1rem;
background-color: #007bff;
color: white;
border: none;
border-radius: 6px;
font-size: 1rem;
font-weight: bold;
cursor: pointer;
transition: background-color 0.2s;
margin-top: 1rem;
}
button:hover {
background-color: #0056b3;
}
.results {
margin-top: 2rem;
padding-top: 1.5rem;
border-top: 1px solid #eee;
}
.result-item {
display: flex;
justify-content: space-between;
margin-bottom: 0.5rem;
font-size: 1.1rem;
}
.result-value {
font-weight: bold;
color: #333;
}
</style>
</head>
<body>
<div class="calculator-card">
<h1>Tip Calculator</h1>
<div class="input-group">
<label for="bill">Bill Amount</label>
<input type="number" id="bill" placeholder="0.00" step="0.01">
</div>
<div class="input-group">
<label for="tip">Tip Percentage (%)</label>
<input type="number" id="tip" placeholder="15" step="1">
</div>
<div class="input-group">
<label for="people">Number of People</label>
<input type="number" id="people" placeholder="1" step="1">
</div>
<button id="calculate">Calculate</button>
<div class="results">
<div class="result-item">
<span>Total Bill:</span>
<span id="total" class="result-value">$0.00</span>
</div>
<div class="result-item">
<span>Each Person Owes:</span>
<span id="perPerson" class="result-value">$0.00</span>
</div>
</div>
</div>
<script>
document.getElementById('calculate').addEventListener('click', function() {
// Get inputs
const billInput = document.getElementById('bill').value;
const tipInput = document.getElementById('tip').value;
const peopleInput = document.getElementById('people').value;
// Parse and clamp Bill
let bill = parseFloat(billInput);
if (isNaN(bill) || bill < 0) {
bill = 0;
}
// Parse and clamp Tip
let tipPercent = parseFloat(tipInput);
if (isNaN(tipPercent) || tipPercent < 0) {
tipPercent = 0;
}
// Parse and clamp People
let people = parseInt(peopleInput, 10);
if (isNaN(people) || people < 1) {
people = 1;
}
// Calculations
const total = bill + (bill * (tipPercent / 100));
const perPerson = total / people;
// Display results formatted to 2 decimal places
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>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background-color: #f0f2f5;
}
.card {
background: white;
padding: 2rem;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
width: 100%;
max-width: 400px;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 1.5rem;
}
.input-group {
margin-bottom: 1rem;
}
label {
display: block;
margin-bottom: 0.5rem;
color: #666;
font-size: 0.9rem;
}
input {
width: 100%;
padding: 0.8rem;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 1rem;
box-sizing: border-box;
}
button {
width: 100%;
padding: 1rem;
background-color: #007bff;
color: white;
border: none;
border-radius: 6px;
font-size: 1rem;
cursor: pointer;
transition: background-color 0.2s;
margin-top: 1rem;
}
button:hover {
background-color: #0056b3;
}
.results {
margin-top: 1.5rem;
padding-top: 1.5rem;
border-top: 1px solid #eee;
}
.result-item {
display: flex;
justify-content: space-between;
margin-bottom: 0.8rem;
font-size: 1.1rem;
}
.result-value {
font-weight: bold;
color: #333;
}
</style>
</head>
<body>
<div class="card">
<h1>Tip Calculator</h1>
<div class="input-group">
<label for="bill">Bill Amount</label>
<input type="number" id="bill" placeholder="0.00" step="0.01">
</div>
<div class="input-group">
<label for="tip">Tip Percentage (%)</label>
<input type="number" id="tip" placeholder="15" step="1">
</div>
<div class="input-group">
<label for="people">Number of People</label>
<input type="number" id="people" placeholder="1" step="1">
</div>
<button id="calculate">Calculate</button>
<div class="results">
<div class="result-item">
<span>Total Bill:</span>
<span class="result-value" id="total">$0.00</span>
</div>
<div class="result-item">
<span>Each Person Pays:</span>
<span class="result-value" id="perPerson">$0.00</span>
</div>
</div>
</div>
<script>
document.getElementById('calculate').addEventListener('click', () => {
// Get inputs
const billInput = document.getElementById('bill').value;
const tipInput = document.getElementById('tip').value;
const peopleInput = document.getElementById('people').value;
// Process bill: treat empty/NaN as 0, clamp negative to 0
let bill = parseFloat(billInput);
if (isNaN(bill) || bill < 0) {
bill = 0;
}
// Process tip: treat empty/NaN as 0, clamp negative to 0
let tipPercent = parseFloat(tipInput);
if (isNaN(tipPercent) || tipPercent < 0) {
tipPercent = 0;
}
// Process people: treat empty/NaN or < 1 as 1
let people = parseInt(peopleInput, 10);
if (isNaN(people) || people < 1) {
people = 1;
}
// Calculations
const total = bill + (bill * (tipPercent / 100));
const perPerson = total / people;
// Formatting to exactly two decimal places
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>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background-color: #f0f2f5;
}
.container {
background: white;
padding: 2rem;
border-radius: 12px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
width: 100%;
max-width: 400px;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 1.5rem;
}
.input-group {
margin-bottom: 1rem;
}
label {
display: block;
margin-bottom: 0.5rem;
color: #666;
font-size: 0.9rem;
}
input {
width: 100%;
padding: 0.75rem;
border: 1px solid #ddd;
border-radius: 6px;
box-sizing: border-box;
font-size: 1rem;
}
button {
width: 100%;
padding: 0.75rem;
background-color: #007bff;
color: white;
border: none;
border-radius: 6px;
font-size: 1rem;
cursor: pointer;
transition: background-color 0.2s;
margin-top: 1rem;
}
button:hover {
background-color: #0056b3;
}
.results {
margin-top: 1.5rem;
padding-top: 1.5rem;
border-top: 1px solid #eee;
}
.result-item {
display: flex;
justify-content: space-between;
margin-bottom: 0.5rem;
font-size: 1.1rem;
}
.result-value {
font-weight: bold;
color: #333;
}
</style>
</head>
<body>
<div class="container">
<h1>Tip Calculator</h1>
<div class="input-group">
<label for="bill">Bill Amount</label>
<input type="number" id="bill" step="0.01" placeholder="0.00">
</div>
<div class="input-group">
<label for="tip">Tip Percentage (%)</label>
<input type="number" id="tip" step="1" placeholder="15">
</div>
<div class="input-group">
<label for="people">Number of People</label>
<input type="number" id="people" step="1" placeholder="1">
</div>
<button id="calculate">Calculate</button>
<div class="results">
<div class="result-item">
<span>Total:</span>
<span class="result-value" id="total">$0.00</span>
</div>
<div class="result-item">
<span>Per Person:</span>
<span class="result-value" id="perPerson">$0.00</span>
</div>
</div>
</div>
<script>
document.getElementById('calculate').addEventListener('click', () => {
// Get values
let billVal = parseFloat(document.getElementById('bill').value);
let tipVal = parseFloat(document.getElementById('tip').value);
let peopleVal = parseInt(document.getElementById('people').value, 10);
// Input Handling: bill and tip
// Treat empty or NaN as 0, and clamp negative to 0
if (isNaN(billVal) || billVal < 0) {
billVal = 0;
}
if (isNaN(tipVal) || tipVal < 0) {
tipVal = 0;
}
// Input Handling: people
// Treat empty, NaN, or < 1 as 1
if (isNaN(peopleVal) || peopleVal < 1) {
peopleVal = 1;
}
// Calculations
const total = billVal + (billVal * (tipVal / 100));
const perPerson = total / peopleVal;
// Format as currency with 2 decimal places
const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2,
maximumFractionDigits: 2
});
document.getElementById('total').textContent = formatter.format(total);
document.getElementById('perPerson').textContent = formatter.format(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>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background-color: #f4f7f6;
}
.card {
background: white;
padding: 2rem;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
width: 100%;
max-width: 400px;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 1.5rem;
}
.input-group {
margin-bottom: 1rem;
}
label {
display: block;
margin-bottom: 0.5rem;
color: #666;
font-size: 0.9rem;
}
input {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 6px;
box-sizing: border-box;
font-size: 1rem;
}
button {
width: 100%;
padding: 12px;
background-color: #007bff;
color: white;
border: none;
border-radius: 6px;
font-size: 1rem;
cursor: pointer;
transition: background-color 0.2s;
margin-top: 1rem;
}
button:hover {
background-color: #0056b3;
}
.results {
margin-top: 2rem;
padding-top: 1.5rem;
border-top: 1px solid #eee;
}
.result-item {
display: flex;
justify-content: space-between;
margin-bottom: 1rem;
font-size: 1.1rem;
}
.result-value {
font-weight: bold;
color: #333;
}
</style>
</head>
<body>
<div class="card">
<h1>Tip Calculator</h1>
<div class="input-group">
<label for="bill">Bill Amount</label>
<input type="number" id="bill" placeholder="0.00" step="0.01">
</div>
<div class="input-group">
<label for="tip">Tip Percentage (%)</label>
<input type="number" id="tip" placeholder="15" step="1">
</div>
<div class="input-group">
<label for="people">Number of People</label>
<input type="number" id="people" placeholder="1" step="1">
</div>
<button id="calculate">Calculate</button>
<div class="results">
<div class="result-item">
<span>Total Bill:</span>
<span class="result-value" id="total">$0.00</span>
</div>
<div class="result-item">
<span>Each Person Pays:</span>
<span class="result-value" id="perPerson">$0.00</span>
</div>
</div>
</div>
<script>
document.getElementById('calculate').addEventListener('click', function() {
// Get inputs
const billInput = document.getElementById('bill').value;
const tipInput = document.getElementById('tip').value;
const peopleInput = document.getElementById('people').value;
// Parse and clamp bill
let bill = parseFloat(billInput);
if (isNaN(bill) || bill < 0) {
bill = 0;
}
// Parse and clamp tip
let tipPercent = parseFloat(tipInput);
if (isNaN(tipPercent) || tipPercent < 0) {
tipPercent = 0;
}
// Parse and clamp people
let people = parseInt(peopleInput, 10);
if (isNaN(people) || people < 1) {
people = 1;
}
// Calculations
const total = bill + (bill * (tipPercent / 100));
const perPerson = total / people;
// Format as currency (ensure 2 decimal places)
const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2,
maximumFractionDigits: 2,
});
document.getElementById('total').textContent = formatter.format(total);
document.getElementById('perPerson').textContent = formatter.format(perPerson);
});
</script>
</body>
</html>