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
8 changes: 8 additions & 0 deletions .idea/.gitignore
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add .idea/ to .gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/Tip-Calculator.iml
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add .idea/ to .gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add .idea/ to .gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add .idea/ to .gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add .idea/ to .gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added design/Matplotlib Chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 55 additions & 21 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,68 @@

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

<title>Frontend Mentor | Tip calculator app</title>
<title>Ofek's Tip calculator</title>
<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=Space+Mono&display=swap" rel="stylesheet">

<!-- 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>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="white-container">
<div class="left-container">

Bill
<div class="bill-input-container">
<label for="bill">Bill</label>
<input type="number" id="bill" name="bill" placeholder="0" class="special-amnt">
</div>
עןא
<div>
<p>Select Tip %</p>
<div class="per-btns-container">
<button onclick="updateTip(5)" class="per-btn" type="button" id="btn-five" >5%</button>
<button onclick="updateTip(10)" class="per-btn" type="button" id="btn-ten">10%</button>
<button onclick="updateTip(15)" class="per-btn" type="button" id="btn-fifteen">15%</button>
<button onclick="updateTip(25)" class="per-btn" type="button" id="btn-twenty-five">25%</button>
<button onclick="updateTip(50)" class="per-btn" type="button" id="btn-fifty">50%</button>
<input type="number" id="custom-tip-input" name="custom-tip-input" placeholder="custom">
</div>
</div>

Select Tip %
5%
10%
15%
25%
50%
Custom
<div class="ppl-input-container">
<label for="ppl-number">Number of People</label>
<input type="number" id="ppl-number" name="ppl-number" placeholder="1" class="special-ppl">
</div>
</div>

Number of People
<div class="right-container">

Tip Amount
/ person
<div class="tip-amount-container">
<div class="flex-box-tip">
<p>Tip amount<br><span style="color:hsl(184, 14%, 56%)">/ person</span></p>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you use inline styling instead of a class and css?

This can cause a mixed style dependencies. pick on styling method and stick with it.

</div>
<div class="flex-box-tip">
<input type="text" id="tip-amount-input" readonly placeholder="$0.00">
</div>
</div>

Total
/ person
<div class="total-container">
<div class="flex-box-total">
<p>Total<br> <span style="color:hsl(184, 14%, 56%)">/ person</span></p>
</div>
<div class="flex-box-total">
<input type="text" id="total-amount-input" readonly placeholder="$0.00">
</div>
</div>
<div class="reset-btn-container">
<button type="button" class="reset-btn" id="reset-btn">Reset</button>
</div>
</div>

Reset
</div>
<script src="script.js"></script>
</body>
</html>
</html>



84 changes: 84 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
let billAmount = 0;
let howManyPpl = 1;
let tipPercentage = 0;
let tipForEach = 0;
let customTipPercentage = 0;

document.getElementById('reset-btn').addEventListener('click', resetValues);

document.getElementById('bill').addEventListener('input', (event) => {
billAmount = Number(event.target.value) || 0;
totalPerPerson();
tipPerPerson();
});

document.getElementById('ppl-number').addEventListener('input', (event) => {
howManyPpl = Number(event.target.value) || 1;
totalPerPerson();
tipPerPerson();
});

document.getElementById('custom-tip-input').addEventListener('input', (event) => {
tipPercentage = 0;
customTipPercentage = Number(event.target.value) || 0;
updateTip(customTipPercentage);
totalPerPerson();
tipPerPerson();
});


function updateTip(newValue) {
if(tipPercentage!==0){
resetCustomTip();
}
tipPercentage = newValue / 100;
totalPerPerson();
tipPerPerson();
console.log("Tip Percentage Updated:", tipPercentage);
}

function totalPerPerson() {

const totalWithTip = billAmount * (1 + tipPercentage);
const result = howManyPpl > 0 ? (totalWithTip / howManyPpl).toFixed(2) : 0;

// הצגת התוצאה בתיבה
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid writing comments in Hebrew.

document.getElementById('total-amount-input').value = `$${result}`;
console.log("bill amount:", billAmount, "num of ppl:", howManyPpl, "tip:", tipPercentage, "result:", result); // הדפסת הערכים בקונסול
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant

}

function tipPerPerson() {

tipForEach = billAmount * (1 + tipPercentage) - billAmount;

const tipRes = howManyPpl > 0 ? (tipForEach / howManyPpl).toFixed(2) : 0;


document.getElementById('tip-amount-input').value = `$${tipRes}`;
console.log( "result:", tipRes); // הדפסת הערכים בקונסול
}

function resetValues() {
// איפוס המשתנים הגלובליים
billAmount = 0;
howManyPpl = 1;
tipPercentage = 0;
tipForEach = 0;
customTipPercentage = 0;

// איפוס תיבות הקלט
document.getElementById('bill').value = '';
document.getElementById('ppl-number').value = '';
document.getElementById('total-amount-input').value = '';
document.getElementById('tip-amount-input').value = '';
document.getElementById('custom-tip-input').value = '';

// חישוב מחדש
totalPerPerson();
console.log("All values reset to default.");
}

function resetCustomTip(){

document.getElementById('custom-tip-input').value = 'Custom';
}
Loading