Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


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


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.


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.


                <!DOCTYPE html>
<html lang="en">
  <!-- Design by -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mortgage Loan Calculator</title>
    <style media="screen">
      background: rgb(8, 144, 110);
      font-family: sans-serif;
    #loancal {
  width: 345px;
  height: 440px;
  color: #fff;
  padding: 10px;
  margin: 100px auto;
h1 {
  text-align: center;
  color: rgb(9, 95, 172);
  margin-bottom: 35px;
  margin-left: 40px;
  margin-right: 40px;
color: rgb(17, 103, 170);
font-size: 17px;
  width: 100%;
  height: 33px;

#interest_rate {
  margin-left: 2px;
   text-align: center;
   color: rgb(6, 111, 139);
   margin-top: 35px;

    <div id="loancal">
        <h1>Loan Calculator</h1>
        <div class="input">
        <p>Loan Amount: $</p>
          <input id="amount" type="number" min="1" max="5000000" onchange="computeLoan()">
        <p>Interest Rate: %</p>
        <input id="interest_rate" min="0" max="100" value="10" step=".1" onchange="computeLoan()">
        <p>Months to Pay: </p>
         <input id="months" type="number" min="1" max="300" value="1" step="1" onchange="computeLoan()">
        <h2 id="payment"></h2>
    <script type="text/javascript">
    function computeLoan(){
        const amount = document.querySelector('#amount').value;
        const interest_rate = document.querySelector('#interest_rate').value;
        const months = document.querySelector('#months').value;
        const interest = (amount * (interest_rate * 0.01)) / months;
        let payment = ((amount / months) + interest).toFixed(2); //calculate monthly payment

        //regedit to add a comma after every three digits
        payment = payment.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); //\B looks for a word boundary, ? says what to look for, \d looks for 3 digits in a row
        document.querySelector('#payment').innerHTML = `Monthly Payment = ${payment}`