diff --git a/index.css b/index.css new file mode 100644 index 0000000..1b64a1f --- /dev/null +++ b/index.css @@ -0,0 +1,169 @@ +body { + color: hsl(186, 14%, 43%); + background-color: hsl(185, 41%, 84%); + font-family: "Space Mono", monospace; + font-weight: 400; + font-style: normal; + margin: 0; + padding: 0; +} + +.firstContainer { + display: flex; + flex-direction: column; + align-items: center; + margin: auto; /*center the elements in the container*/ + text-align: center; + padding: 2rem; + width: 90%; + max-width: 50rem; +} + +.calculator { + margin-top: 2rem; + background-color: white; + display: flex; + flex-wrap: wrap; /*responsive*/ + align-items: center; + justify-content: space-between; + padding: 1rem; + border-radius: 0.625rem; +} + +.input-bill { + flex: 1; + min-width: 15rem; /* adjust to smaller screens */ + display: flex; + flex-direction: column; + gap: 1rem; + text-align: left; + padding: 1rem; +} + +.output-bill{ + flex: 1; + min-width: 15rem; /*adjust to smaller screens*/ +} + + +.input-icon { + position: relative; + width: 100%; +} + +.input-icon input { + background-color: hsl(189, 41%, 97%); + width: 70%; + padding-left: 2.5rem; + padding-right: 1rem; + height: 2rem; + font-size: 1rem; + border: 0.063rem solid #ccc; + border-radius: 0.5rem; +} + +.input-icon img { + position: absolute; + top: 50%; + left: 0.625rem; + height: 1rem; + transform: translateY(-50%); + width: auto; + pointer-events: none; +} + +.tip-btn { + display: inline-flex; + gap: 0.5rem; + margin-top: 0.5rem; + width: 6rem; + height: 2.5rem; + cursor: pointer; + background-color: hsl(183, 100%, 15%); + color: white; + border: none; + font-family: "Space Mono", monospace; + font-weight: 400; + font-style: normal; + border-radius: 0.5rem; + justify-content: center; + padding: 0.5rem; +} + +.tip-btn:hover { + background-color: hsl(172, 67%, 45%); +} + +#custom-btn:hover { + background-color: hsl(172, 67%, 45%); +} + +#custom-btn { + background-color: hsl(189, 41%, 97%); + color: hsl(186, 14%, 43%); + font-family: "Space Mono", monospace; + font-weight: 400; + font-style: normal; +} + +.output-bill{ + text-align: left; + background-color: hsl(183, 100%, 15%); + border-radius: 0.5rem; + padding: 1rem; +} + +#reset-btn { + text-align: center; + width: 90%; + height: 2.5rem; + border: none; + cursor: pointer; + background-color: hsl(172, 67%, 45%); + color: hsl(183, 100%, 15%); + font-family: "Space Mono", monospace; + font-weight: 400; + font-style: normal; + display: block; + margin: 1rem auto; /* center the button*/ + border-radius: 0.5rem; +} + +div h2 { + color: hsl(172, 67%, 45%); +} + +div p span { + color: hsl(186, 14%, 43%); +} + +.results { + display: flex; + justify-content: space-between; +} + +.reset { + margin-top: 5rem; +} + + +@media (max-width: 375px) { + .container { + padding: 1rem; + width: 100%; /* full size in smaller screens */ + } + + .calculator { + flex-direction: column; + gap: 1rem; + } + + .output-bill, + .input-section { + min-width: 100%; /* maximize the space*/ + } + + .tip-btn { + width: 100%; + } +} diff --git a/index.html b/index.html index 5c09e8d..4d14b7c 100644 --- a/index.html +++ b/index.html @@ -5,35 +5,64 @@ - + Frontend Mentor | Tip calculator app - - + + + + + - - - Bill - Select Tip % - 5% - 10% - 15% - 25% - 50% - Custom - - Number of People + + +
+ logo +
+ +
+ +
+ + dollar icon +
+ + +
+ + + + + + +
- Tip Amount - / person + +
+ + person icon +
+ - Total - / person +
- Reset + +
+
+

Tip Amount
/ person

+

$0.00

+
+
+

Total
/ person

+

$0.00

+
+
+ +
+
+
+
+ \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..22de4f0 --- /dev/null +++ b/index.js @@ -0,0 +1,37 @@ +let bill = 0; +let numberPeople = 0; +let tip = 0; + +// 讛讛讝谞讛 诇诇讞爪谉 讟讬驻 +const calcTip = (t) => { + tip = t; +} +// 诪讛 砖讛诪砖转诪砖 讛讻谞讬住 讬讚谞讬转 (讻诪讜转 讜诪住驻专 讞砖讘讜谉) +const allUpdate = () => { + bill = document.getElementById("bill").value; + numberPeople = document.getElementById("people").value; +} + + +const test = () => { + if (isNaN(bill) || bill <= 0) { + alert("Please enter a valid bill amount"); + return; + } + //讛讻谞住转 诪住驻专 砖诇讬诇讬 砖诇 讗谞砖讬诐 + if (isNaN(numberPeople) || numberPeople <= 0) { + alert("Please enter a valid number of people"); + return; + } + const tipAmount = ((bill * tip) / 100) / numberPeople; // 诇讻诇 讘谞讗讚诐- 讞讬砖讜讘 讛转砖诇讜诐 注诐 讛讗讞讜讝-TIP AMOUNT + const totalofperson = (bill / numberPeople) + tipAmount; + + document.getElementById("tip-amount").innerHTML = `$${tipAmount.toFixed(2)}`;//讛转讜爪讗讛 注诐 砖转讬 住驻专讜转 讗讞专讬 讛谞拽讜讚讛 + document.getElementById("total").innerHTML = `$${totalofperson.toFixed(2)}`; +} + +//讛拽砖讘讛 诇讘讞讬专转 讛诪砖转诪砖 +document.getElementById("bill").addEventListener("input", allUpdate); +document.getElementById("people").addEventListener("input", allUpdate); +document.getElementById("submit-btn").addEventListener("click", test); +