'Coding Challenge #4'

Udemy complete javascript course. Fundamentals I

by trentHarlem

HTML

<h2>
Coding Challenge #4
</h2>

<p>
Steven wants to build a very simple tip calculator for whenever he goes eating in a restaurant. In his country, it's usual to tip 15% if the bill value is between 50 and 300. If the value is different, the tip is 20%.
</p>

<p>
1. Your task is to calculate the tip, depending on the bill value. Create a variable called 'tip' for this. It's not allowed to use an if/else statement. (Tip: start with an if/else statement, and then convert it to a ternary operator!)<br>
2. Print a string to the console containing the bill value, the tip, and the final value (bill + tip). Example: 'The bill was 275, the tip was 41.25, and the total value 316.25'
</p>

<p>
TEST DATA: Test for bill values 275, 40 and 430
</p>
<p>
HINT: To calculate 20% of a value, simply multiply it by 20/100 = 0.2<br>
HINT: Value X is between 50 and 300, if it's >= 50 && <= 300

</p>

GOOD LUCK 😀

CSS

html {
  font: 18px system-ui;
}

JavaScript

//let bill = 275 // total 316.25
let bill = 40  // 48
//let bill  = 430 // 516

let tip15 = bill * 0.15
let tip20 = bill * 0.20

const tip = (bill >= 50 && bill <= 300) ? tip15: tip20

console.log(`Your bill was $${bill}, you tipped $${tip}, the total is $${bill+tip}`)