Pen Settings

HTML

CSS

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

JavaScript

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

Behavior

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.

HTML

              
                <!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link href='https://fonts.googleapis.com/css?family=Alegreya Sans SC' rel='stylesheet'>
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <div class="layout">
    <h1> Tip Calculator </h1>
    <div class="information-layout">
      <form>
        <p>How much was the bill:</p>
        <input type="text" id="billAmount">
        <p>How much is the service charge?</p>
<!--         <select id="service">
        <option default>-- Select Your Service --</option>
        <option value="0.125">Amazing - 12.5%</option>
        <option value="0.10">Good - 10%</option>
        <option value="0.025">Bad - 2.5%</option>
        <option value="0">No Service - 0%</option>
        <option value="-0.10">Horrible 10% off</option>
      </select> -->
        <input id="service"> 
        <p> How many people are sharing the bill:</p>
        <input type="text" id="peopleAmount">
      </form>
      <div class="cal" id="calculate" onclick="Output()"> Calculate</div>
      <h3 id="result">The Information Will be displayer here</h3>
    </div>
  </div>
  <script src="controls.js"></script>
</body>

</body>

</html>
              
            
!

CSS

              
                body {
  background: lightblue;
  font-family: "Alegreya Sans SC";
}

.layout {
  border: 1px solid;
  width: 25em;
  height: 540px;
  margin: 50px auto;
  border-radius: 10%;
  background: rgb(77, 0, 0);
}

.layout h1 {
  font-size: 50px;
  text-align: center;
  color: white;
}

.information-layout {
  background: white;
  padding: 10px;
  border-radius: 10%;
  margin: 0 auto;
}

.information-layout p{
  text-align: left;
  margin: auto 20px;
  font-size: 20px;
}
.information-layout h3 {
  font-size: 20px;
  text-align: center;
}

.information-layout input {
  width: 10em;
  padding: 5px;
  font-size: 20px;
  margin: 10px 4%;
}
.information-layout select {
  width: 15em;
  margin: 10px 4%;
  height: 50px;
  font-size: 20px;
}

.information-layout .cal{
  font-size: 3em;
  text-align: center;
  padding: 5px;
  border: 1px solid #8a2807;
  color: white;
  background: #8a2807;
  width: 5em;
  margin: 10px auto;
  border-radius: 30px;
  cursor: pointer;
}

              
            
!

JS

              
                function Output() {
  let bill = document.getElementById("billAmount").value;
  let people = document.getElementById("peopleAmount").value;
  let serviceRating = document.getElementById("service").value;

  //validate input
  if (serviceRating === null) {
    alert("Please select a service");
    return;
  }
  if (bill === "") {
    alert("Please enter values");
    document.getElementById("result").innerHTML = "Please enter values";
    return;
  }
  //Check to see if this input is empty
  if (people === "") {
    alert("Please eneter amount of people");
    document.getElementById("result").innerHTML =
      "Please enter the amount of people";
    return;
  }
  if (bill === "" && people === "" && serviceRating === "") {
    alert("No values were entered");
    document.getElementById("result").innerHTML = "No values were entered";
    return;
  }

  //Calculate tip
  var total = bill * (serviceRating/100) / people;

  console.log("bill: " + bill);
  console.log("service" + serviceRating);
  console.log(total);

  var amountOfPeople = bill / people;

  total = total + amountOfPeople;
  console.log(total + " total overall");
  //round to two decimal places
  total = Math.round(total * 100) / 100 *(10/100);
  total = total.toFixed(2);
  document.getElementById("result").innerHTML = "Each person tips: £" + total;

  //click to call function
  document.getElementById("calculate").onclick = function() {
    Output();
  };
}

              
            
!
999px

Console