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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                12<!-- write up at: https://lynnamacher.com/tip-calculator-programs/ -->
<!--10/09/19 done, final updates-->
<!DOCTYPE html>
<html lang="en">

<head>
  <link href="tip.css" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Ubuntu+Condensed&display=swap" rel="stylesheet">
</head>
<body>
  <div id="container">
    <h1>Bill Splitter and Tip Calculator</h1>

    <form>
      <p>Amount of Bill: </p>
      <p>$ <input type="text" class="fillBox" id="amtbill" placeholder="Amount Of Bill"> </p>


        <p>How was the service? </p>
      <p><select id="servicelevel">
        <option disabled selected value="0">Select an option</option>
        <option value="0.12">Great 12%</option>
        <option value="0.1">Good 10%</option>
        <option value="0.07">OK 7%</option>
        <option value="0.05">Poor 5%</option>
        <option value="0.01">Horrible 1%</option></select>
       </p>

       <p>How many people are splitting the bill?</p>
       <p><input type="text" class="fillBox" id="numpeople" placeholder="Number of People"> </p>


<button type="button" id="calculate"> Calculate Totals</button>
    </form>
    <div id="totalArea">
<div id="billSplit">
  <sup>$</sup><span id="split">0.00</span>
  <small id="each">per person</small>
</div>

    <div id="totalTip">
      <sup>$</sup><span id="tip">0.00</span>
      <small id="each2">per person</small>
    </div>

    <div id="grandTotal">
      <sup>$</sup><span id="grand">0.00</span>
      <small id="each3">per person</small>
    </div>
  </div>
    <script type="text/javascript" src="tipcalc.js"></script>
  </div>
  </body>
</html>

              
            
!

CSS

              
                html {
  background-color: #013982;
  font-family: 'Ubuntu Condensed', sans-serif;
}
p{
  font-size: 1.2em;
}
#container {
  background-color: #fff;
  width: 600px;
  height: 625px;
  border-radius: 25px;
  margin: 25px auto;
}

H1 {
  text-align: center;
  color: white;
  background-color: #000;
  padding: 5px;
  border-radius: 25px 25px 0px 0px;
}

form {
  padding-left: 10px;
  font-size: 1.2em;
}

.fillBox {
  width: 95%;
  height: 23px;
  padding: 2 px 7px;
  font-size: 1.1em;
}

.totalArea {
  width: 585px;
  height: 20px;
  font-size: 1.2em;
}

#servicelevel {
    width: 98%;
    height: 40px;
    padding-left: 6px;
    padding-bottom: 4px;
    font-size: 1.1em;
}

button {
  font-size: 25px;
  display: block;
  margin: 30px auto;
  border-radius: 25px;
  color: white;
  background-color: #7299cc;
}

#totalArea {
width: 590px;
margin-left: 5px;
align-items: stretch;
}
sup {
  font-size: 1.5em;
  top: -13px;
}

small {
  font-size: 1.2em;
  font-weight: bold;
  display: block;
}

#tip {
  font-size: 2.5em;
}

#totalTip {
  font-size: 1.2em;
  margin-top: 5px;
  text-align: center;
  float: left;
  width: 190px;
}

#totalTip:before {
  content: "Tip Amount:";
  font-size: 1.2em;
  font-weight: bold;
  display: block;
  text-transform: uppercase;
}

#split {
  font-size: 2.5em;
}


#billSplit {
  font-size: 1.2em;
  margin-top: 5px;
  text-align: center;
  float: left;
  width: 190px;
  border-right: 2px solid #555;
}

#billSplit:before {
  content: "Bill:";
  font-size: 1.2em;
  font-weight: bold;
  display: block;
  text-transform: uppercase;
}

#grand {
  font-size: 2.5em;
}

#grandTotal {
  font-size: 1.2em;
  margin-top: 5px;
  text-align: center;
  margin-left: 0px;
  float: left;
  width: 190px;
    border-left: 2px solid #555;
}

#grandTotal:before {
  content: "Grand Total:";
  font-size: 1.2em;
  font-weight: bold;
  display: block;
  text-transform: uppercase;
}

              
            
!

JS

              
                //Hide the tip amount on load
document.getElementById("totalTip").style.display = "none";
document.getElementById("billSplit").style.display = "none";
document.getElementById("grandTotal").style.display = "none";
//document.getElementById("each").style.display = "none";

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

//PUll in variables from form
function calculateTip() {
  var billAmt = document.getElementById("amtbill").value;
  var serviceLevel = document.getElementById("servicelevel").value;
  var numPeople = document.getElementById("numpeople").value;

  //Checks to make sure they are numbers only
  if(isNaN(document.getElementById("amtbill").value) || isNaN(document.getElementById("numpeople").value)){
    alert("Please enter numbers only");
    location.reload();
   }else{ }


  //validate inputs
  if (billAmt === "" || serviceLevel == 0) {
    alert("Please enter values");
    return;
  }
  //Check to see if this input is empty or less than or equal to 1
  if (numPeople === "" || numPeople <= 1) {
    numPeople = 1;
    document.getElementById("each").style.display = "none";
    document.getElementById("each2").style.display = "none";
    document.getElementById("each3").style.display = "none";
    document.getElementById("billSplit").style.display = "none";
  } else {
    document.getElementById("each").style.display = "block";
    document.getElementById("each2").style.display = "block";
    document.getElementById("each3").style.display = "block";
  }

  //Calculate bill splitting
  var billTotal = billAmt / numPeople;

  //Calculate tip amount
  var total = (billAmt * serviceLevel) / numPeople;

  //calculate total
  var grandTotal = billTotal + total;

  //round to two decimal places
  total = Math.round(total * 100) / 100;
  billTotal = Math.round(billTotal * 100) / 100;
  grandTotal = Math.round(grandTotal * 100) / 100;

  //next line allows us to always have two digits after decimal point
  total = total.toFixed(2);
  billTotal = billTotal.toFixed(2);
  grandTotal = grandTotal.toFixed(2);

//Display the split total
//if there is only 1 hide this area
if (numPeople === "" || numPeople <= 1) {
  numPeople = 1;
  document.getElementById("billSplit").style.display = "hidden";
  document.getElementById("split").innerHTML = billTotal;
} else {
    document.getElementById("billSplit").style.display = "block";
    document.getElementById("split").innerHTML = billTotal;
}
//Display the tip
    document.getElementById("totalTip").style.display = "block";
    document.getElementById("tip").innerHTML = total;

//Display the Grand Totals
    document.getElementById("grandTotal").style.display = "block";
    document.getElementById("grand").innerHTML = grandTotal;
}

              
            
!
999px

Console