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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <header>
  <div class="header-container">
    <img src="https://drive.google.com/uc?export=view&id=1ImJMbwCoNuouMYx5u7dRjqG5dCjvQsWP">
    <h2>素人エンジニアの苦悩</h2>
  </div>
</header>
<main>
  <div class="main-container">
    <div class="discription">
      <h1>つみたてNISA<br>シミュレーター</h1>
      <p>つみたてNISAで20年間積立すると、運用益はどれくらいになるでしょうか?</p>
      <p>定額積立・年利一定という条件で、運用益を計算してみましょう!</p>
      <p>毎月の積み立て額と年利を記入して、計算するをクリックしてください</p>
    </div>
    <div class="form-container">
      <h2>20年間積み立てた時の運用益を計算します</h2>
      <form id="invest-form">
        <div>
          <label for="invest-amount">毎月の積立額</label><br>
          <input type="number" id="invest-amount" name="amount" value="1000"> 円
        </div>
        <div>
          <label for="invest-rate">年利</label><br>
          <input type="number" id="invest-rate" name="rate" value="5"> %
        </div>
      </form>
      <div>
        <button type="buton" onclick="changeValue()">計算する</button>
      </div>
    </div>
    <div class="view-container">
      <div  class="view-box" id="principal-amount">
        <p>合計積み立て金額</p>
        <p class="inline-text"><strong>0</strong>円</p>
      </div>
      <div class="view-box" id="profit">
        <p>運用収益額</p>
        <p class="inline-text"><strong>0</strong>円</p>
      </div>
      <div class="view-box" id="total-assets">
        <p>総資産額</p>
        <p class="inline-text"><strong>0</strong>円</p>
      </div>
    </div>
  </div>
</main>
              
            
!

CSS

              
                @charset "utf-8";

html {
  font-size: 16px;
}

@media (max-width:720px) {
  html {
  font-size: 14px;
  }
}

html * {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #d8eefe;
  font-family: sans-serif;
}

h1, h2 {
  color: #094067;
}

p {
  color: #5f6c7b;
}

input[type=number] {
  color: #5f6c7b;
  border: none;
  border-radius: 5px;
  cursor: pointer
}

button {
  display: inline-flex;
  padding: 8px 16px;
  color: #fffffe;
  font-size: 1rem;
  border: none;
  border-radius: 5px;
  background: #3da9fc;
  cursor: pointer
}

button:hover {
  opacity: 0.8;
  font-weight: bold;
}

header {
  color: #094067
}

.header-container {
  margin: 0 auto;
  padding: 30px 20px 10px 40px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.header-container > img {
  width: 2.5rem;
  margin-right: 15px;
  border: 1px solid #094067;
  border-radius: 50px;
}

.main-container {
  margin: 0 40px;
}

.discription {
  margin: 80px auto;
}

.discription > h1 {
  margin-bottom: 50px;
  padding: 0;
  font-size: 2.8rem;
}

.form-container {
  margin: 0 auto;
  color: #5f6c7b;
}
.form-container > h2 {
  padding-top: 50px
}
.form-container > div {
  margin: 80px auto;
  text-align: center;
}

#invest-form {
  margin: 90px auto;
  display: flex;
  justify-content: space-between;
}

#invest-form > div {
  padding-left: 8%;
  margin: 10px;
  width: 50%;
}

#invest-form input[type=number] {
  text-align: right;
  width: 9rem;
  height: 3rem;
  font-size: 2rem;
}

@media (max-width:720px) {
  #invest-form {
    flex-wrap: wrap;
  }
  #invest-form > div {
    width: 100%;
  }
}

.view-container {
  margin: 60px auto;
  padding: 0;
  display: flex;
  justify-content: space-between;
}

.view-box {
  width: 33%;
  margin: 10px;
  padding: 20px 0px;
  border: 2px solid #fff;
  border-radius: 20px;
  background: #fffffe;
  color: #fff;
  text-align: center;
}

@media (max-width:720px) {
  .view-container {
    flex-wrap: wrap;
  }
  .view-box {
    width: 100%;
  }
}

.inline-text {
  display: inline;
}

.inline-text > strong {
  font-size: 1.6rem;
}
              
            
!

JS

              
                const formElm = document.getElementById("invest-form");
const prinAmtDiv = document.querySelector('#principal-amount strong'); 
const profitDiv = document.querySelector('#profit strong'); 
const assetsDiv = document.querySelector('#total-assets strong'); 

function changeValue() {
  let profit = 0;
  let amount = formElm.amount.value
  let mRate = monthlyRate(formElm.rate.value);
  let numOfMonth = 20 * 12;
  let prinAmt = amount * numOfMonth;
  for (let i=0; i<numOfMonth; i++) {
    profit += calMonthlyProfit(amount, mRate, i);
  }
  profit = Math.floor(profit);
  prinAmtDiv.innerHTML = Number(prinAmt).toLocaleString();
  profitDiv.innerHTML = "+" + Number(profit - prinAmt).toLocaleString();
  assetsDiv.innerHTML = Number(profit).toLocaleString();
}

function monthlyRate(annualrate){
  return Math.pow(1 + annualrate/100, 1/12) -1;
}

function calMonthlyProfit(amount, mRate, num) {
  return amount * Math.pow((1 + mRate),num);
}


              
            
!
999px

Console