Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 217 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
html{
background: hsl(185, 41%, 84%);
font-family: 'Space Mono', monospace;
}

.container{
display: flex;
justify-content: space-between;
flex-direction: row;
background: white;
border-radius: 20px;
padding: 30px;
width: 700px;
margin: 0 auto;
margin-top: 3%;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
color: hsl(186, 14%, 43%);
margin-bottom: 10%;
font-weight: 700;

}

header{
display: flex;
flex-direction: column;
align-items: center;
margin-top: 40px;
font-size: 20px;
color: hsl(183, 100%, 15%);
}

.input-container p {
font-size: 16px;
text-align: left;
font-weight: bold;
}



.dollar-icon {
padding-left: 25px;
background: url("./images/icon-dollar.svg") no-repeat left;
background-size: 20px;
transform: translateY(-50%);
pointer-events: none; /* Prevent interaction with the symbol */
color: #aaa;
}

.person-icon {
position: absolute;
left: 26.5%;
top: 75.7%;
transform: translateY(-50%);
pointer-events: none; /* Prevent interaction with the symbol */
color: #aaa;
}


.bill-input {
background: url("./images/icon-dollar.svg") no-repeat left;
background-size: 17px;
font-family: 'Space-Mono' ,monospace;
font-weight: bold;
font-display: right;
color: hsl(183, 100%, 15%);
direction: rtl; /* Right to left */
width: 100%;
padding: 10px 10px 10px 30px; /* Padding to leave space for the dollar sign */
font-size: 21px;
border: none;
border-radius: 10px;
box-sizing: border-box;
background-color: hsl(189, 41%, 97%);
}

.people-input {
background: url("./images/icon-person.svg") no-repeat left;
background-size: 17px;
font-family: 'Space-Mono' ,monospace;
font-weight: bold;
font-display: right;
color: hsl(183, 100%, 15%);
direction: rtl; /* Right to left */
width: 100%;
padding: 10px 10px 10px 30px; /* Padding to leave space for the dollar sign */
font-size: 21px;
border: none;
border-radius: 10px;
box-sizing: border-box;
background-color: hsl(189, 41%, 97%);
}

input::placeholder {
color: hsl(186, 14%, 43%);
}


.selection-container {
text-align: center;
max-width: 300px;
}

.selection-container p {
font-size: 16px;
text-align: left;
margin-bottom: 10px;
font-weight: bold;
}

.tip-buttons {
display: grid;
grid-template-columns: repeat(3, 1fr); /* 3 columns */
gap: 10px; /* Space between items */
}

.tip-button, .custom-tip {
border: none;
font-family: 'Space Mono', monospace;
font-weight: bold;
padding: 10px;
font-size: 20px;
border-radius: 5px;
text-align: center;
box-sizing: border-box;
cursor: pointer;
}

.tip-button {
background-color: hsl(183, 100%, 15%);
color: white;
transition: background-color 0.3s;
}

.tip-button:hover {
background-color: hsl(172, 67%, 45%);
color: hsl(183, 100%, 15%);
}

.custom-tip {
background-color: hsl(189, 41%, 97%);
font-size: 16px;
width: 100%;
}

.tip-amount {
display: flex;
justify-content: space-between;
padding: 20px;
background-color: hsl(183, 100%, 15%);
color: white;
}

.total-amount{
display: flex;
justify-content: space-between;
padding: 20px;
background-color: hsl(183, 100%, 15%);
color: white;
}
output {
margin-top: 20px;
font-size: 30px;
font-weight: bold;
color: hsl(172, 67%, 45%);
}


.output-container {
margin-top: 5px;
padding: 20px;
width: 45%;
background-color: hsl(183, 100%, 15%);
border-radius: 10px;
color: white;
}

.tip-amount-value{
margin-top: 0;
font-size: 10px;

}

.total-amount-value{
margin-top: 0;
font-size: 10px;
}

.reset-button{
margin-top: 50px;
width: 100%;
padding: 10px;
font-size: 15px;
border-radius: 10px;
border: none;
text-align: center;
cursor: pointer;
background-color: hsl(172, 67%, 45%);
color: hsl(183, 100%, 15%);
}




/* Media query for mobile devices */
@media (max-width: 1030px) {
.container{
flex-direction: column;
height: 75%;
width: 100%;
}

.output-container{
margin-top: 3%;
width: 90%;
}

}
74 changes: 53 additions & 21 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,67 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- displays site properly based on user's device -->

<link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png">
<link rel="stylesheet" href="index.css">

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Caveat:wght@400..700&family=New+Amsterdam&family=Space+Mono:ital,wght@0,400;0,700;1,400;1,700&family=Ubuntu:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700&display=swap" rel="stylesheet">

<title>Frontend Mentor | Tip calculator app</title>
<title>Tip calculator app</title>

<!-- Feel free to remove these styles or customise in your own stylesheet 👍 -->
<style>
.attribution { font-size: 11px; text-align: center; }
.attribution a { color: hsl(228, 45%, 44%); }
</style>
</head>
<body>
<header>
<div>SPLI</div>
<div>TTER</div>
</header>
<div class="container">
<div class="input-container">
<div class="bill-container">
<p>Bill</p>
<input type="text" id="bill-input" class="bill-input" placeholder="0.00">
</div>


Bill
<div class="selection-container">
<p>Select Tip %</p>
<div class="tip-buttons">
<button class="tip-button" onclick="calculateTip(1.05)">5%</button>
<button class="tip-button" onclick="calculateTip(1.1)">10%</button>
<button class="tip-button" onclick="calculateTip(1.15)">15%</button>
<button class="tip-button" onclick="calculateTip(1.25)">25%</button>
<button class="tip-button" onclick="calculateTip(1.50)">50%</button>
<input type="text" class="custom-tip" placeholder="Custom">
</div>
</div>

Select Tip %
5%
10%
15%
25%
50%
Custom
<div class="people-container">
<p>Number of People</p>
<input type="number" id="num-of-people-input" class="people-input" placeholder="0" oninput="updatePeople()">
</div>
</div>


<div class="output-container">

Number of People
<div class="tip-amount">
<div class="output">
<p>Tip Amount</p>
<p class="tip-amount-value">/ person</p>
</div>
<output class="tip-amount-output" id="tip-amount">$0.0</output>
</div>

Tip Amount
/ person
<div class="total-amount">
<div class="output">
<p>Total</p>
<p class="total-amount-value">/ person</p>
</div>
<output class="total-amount-output" id="total-amount">$0.0</output>
</div>

Total
/ person
<button class="reset-button" onclick="reset()">RESET</button>
</div>

Reset
<script src="index.js"> defer</script>
</body>
</html>
32 changes: 32 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
let totalAmount;


const calculateTip = (tipPercentage) => {
const amount = document.getElementById('bill-input').value;
if (amount === '') {
alert('Please enter the amount of bill');
return;
}
else{
totalAmount = amount*tipPercentage;
}
document.getElementById('tip-amount').innerHTML = (totalAmount - amount).toFixed(2) + "$";
};

const updatePeople = () => {
const numberOfPeople = document.getElementById('num-of-people-input').value;
const amount = document.getElementById('bill-input').value;
if (numberOfPeople == 0 || amount === '') {
alert('Please enter the number of people');
return;
}
perPersonAmount = (totalAmount/numberOfPeople).toFixed(2);
document.getElementById('total-amount').innerHTML = perPersonAmount + "$";
};

const reset = () => {
document.getElementById('bill-input').value = '';
document.getElementById('num-of-people-input').value = '';
document.getElementById('tip-amount').innerHTML = '0.00$';
document.getElementById('total-amount').innerHTML = '0.00$';
}