Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.



<title>Tip Calculator</title>

<body id="container">
  <h1>Tip Calculator</h1>
  <Label id="billLabel">Enter Bill $</label>
  <input  type="text" id="billInput">
  <br> </br>  
  <label id="quality">Quality of Service</label>
  <select id="qualitySelector">      >
    <option disabled selected>Please select one</option>
    <option value=".25">Supurb 25%</option>
    <option value=".20">Very Good 20%</option>
    <option value=".15">Good 15%</option>
    <option value=".10">Fair 10%</option>

  <label id="people">How many people?</label>
  <input  type="text"id="totalPeople" >

 <button type="button" id="btn">Calculate</button>

<div id="results">
  <p id="your-tip">Tip is</p>
  <sup>$</sup> <span id="tip">0.00</span>
  <p id="Each">Each</p>


    font-family: sans-serif;
  background: #71d13a;
  background: linear-gradient(to right, #8785ff, #89ffff);

#container {
 background: #f4f7ca;
  width: 400px;
    height: 400px;
    padding: 10px 20px 10px 20px;
    position: absolute;
    top: 10%;
    left: 50%;
    margin-left: -200px;
    z-index: 2;   
    border: solid 2px #2D0238;
    border-radius: 15px;
    box-shadow: 4px 4px 5px #8b8484;

  text-align: center;

#btn {
  display: block;
  width: 100px;
  height: 35px;
  border-radius: 10px;
  font-size: 20px;
  background: #49eef7;

  font-weight: bold;

  font-weight: bold;

#people {
  font-weight: bold;

#results {
  font-weight: bold;
  font-size: 20px;  

#tip {
  font-size: 30px;


                //Define variables
function calculateTip(){
    let billAmt = document.getElementById("billInput").value; // JS only use capital letter at the begining for classes
    let servQual = document.getElementById("qualitySelector").value;
    let numPeople = document.getElementById("totalPeople").value;
    let tipAmount;
    //validating input
    if (billAmt === "" || servQual === 0) { // you must use a logical operator to compare to zero
      window-alert("Please provide requested values.");
    //still validating input
    if (numPeople === "" || numPeople <=1) {
      numPeople = 1;
    }  else {
      document.getElementById("results").style.display = "block";
    //calculating the tip amount
    tipAmount = (billAmt*servQual)/numPeople;
    tipAmount = Math.round(tipAmount * 100)/ 100;
    tipAmount = tipAmount.toFixed(2);
    document.getElementById("tip").innerText = tipAmount;  
    // document.getElementById("results").style.display = "none"; ---> Why are you hiding the result?
    document.getElementById("btn").onclick = function() {calculateTip()};