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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.


<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()};
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.