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

              
                <div class="wrapper">
    <header>
      <div class="container">
        <div class="row align-items-center">
          <div class="col-lg-3">
            <div class="logo">
              <img src="https://hexschool.github.io/JavaScript_HomeWork/assets/BMICLogo.png" alt="BMICLogo" class="img-fluid">
            </div>
          </div>
          <div class="col-lg-6">
            <form class="BMI-form">
              <div class="form-group pb-1">
                <label>身高 cm</label>
                <input class="form-control" id="heightEl" placeholder="請輸入身高">
              </div>
              <div class="form-group">
                <label>體重 kg</label>
                <input class="form-control" id="widthEl" placeholder="請輸入體重">
              </div>
            </form>
          </div>
          <div class="col-lg-3 d-flex align-items-center justify-content-responsive">
            <div class="submit">
              <button type="submit" class="btn submit-btn">看結果</button>
            </div>
            <div class="results-block">
              <div class="results">
                <h1 class="results-BMI">20.90</h1>
                <p>BMI</p>
                <button class="btn return"><img src="https://hexschool.github.io/JavaScript_HomeWork/assets/icons_loop.png" alt="return"></button>
              </div>
              <h1>理想</h1>
            </div>
          </div>
        </div>
      </div>
    </header>
    <section>
      <div class="main">
        <div class="container">
          <div class="content">
            <h2>BMI 紀錄</h2>
            <div class="data-list">
            </div>
          </div>
        </div>
      </div>
    </section>
    <footer>
      <div class="text-center">
        <img src="https://hexschool.github.io/JavaScript_HomeWork/assets/BMICLogo.png" alt="BMI-logo" class="img-fluid">
      </div>
    </footer>
  </div>
              
            
!

CSS

              
                @charset "UTF-8";
@import url(https://fonts.googleapis.com/earlyaccess/notosanstc.css);
*,
*:active,
*:focus,
*:hover,
*:link,
*:visited {
  -o-transition: background-color 0.2s linear, border-color 0.1s linear;
  -webkit-transition: background-color 0.2s linear, border-color 0.1s linear;
  -moz-transition: background-color 0.2s linear, border-color 0.1s linear;
  transition: background-color 0.2s linear, border-color 0.1s linear; }

/* ------- 標頭設計(字級,字距,顏色) ------- */
html {
  font-size: 15px; }

body {
  font-family: arial,'Noto Sans TC','微軟正黑體', sans-serif; }

header {
  background-color: #424242;
  padding: 4.5rem; }
  header .logo {
    text-align: right; }
  header .BMI-form label {
    color: #FFD366;
    font-size: 1.2rem; }
  header .BMI-form input {
    background-color: rgba(255, 255, 255, 0.18);
    color: rgba(255, 255, 255, 0.5);
    border: 1px solid #FFD366;
    -ms-border-radius: 10px;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    border-radius: 10px;
    font-size: 1.5rem; }
  header .submit-btn {
    color: #424242;
    background: #FFD366;
    width: 120px;
    height: 120px;
    -ms-border-radius: 50%;
    -moz-border-radius: 50%;
    -webkit-border-radius: 50%;
    border-radius: 50%;
    font-size: 1.5rem; }
    header .submit-btn:hover {
      -webkit-box-shadow: 0px 1px 6px 3px rgba(255, 197, 50, 0.64);
      -ms-box-shadow: 0px 1px 6px 3px rgba(255, 197, 50, 0.64);
      box-shadow: 0px 1px 6px 3px rgba(255, 197, 50, 0.64); }
    header .submit-btn:focus {
      -webkit-box-shadow: none;
      -ms-box-shadow: none;
      box-shadow: none; }
    header .submit-btn:active {
      background: #DEA821;
      -webkit-box-shadow: none;
      -ms-box-shadow: none;
      box-shadow: none; }
  header .results-block {
    display: none;
    -webkit-align-items: center;
    align-items: center;
    -webkit-box-align: center;
    -ms-flex-align: center; }
    header .results-block .results {
      width: 130px;
      height: 130px;
      border: 6px solid;
      -ms-border-radius: 50%;
      -moz-border-radius: 50%;
      -webkit-border-radius: 50%;
      border-radius: 50%;
      text-align: center;
      position: relative;
      padding: 2.5rem 0 2rem; }
      header .results-block .results h1 {
        font-size: 2rem;
        margin-bottom: .25rem;
        padding-left: 0; }
      header .results-block .results p {
        font-size: 1rem;
        margin-bottom: 0; }
      header .results-block .results .return {
        border: 3px solid #424242;
        -ms-border-radius: 50%;
        -moz-border-radius: 50%;
        -webkit-border-radius: 50%;
        border-radius: 50%;
        position: absolute;
        right: -5%;
        bottom: -5%; }
    header .results-block h1 {
      font-size: 1.8rem;
      padding-left: 1rem; }
    header .results-block.ideal .results {
      border-color: #86D73F; }
      header .results-block.ideal .results h1,
      header .results-block.ideal .results p {
        color: #86D73F; }
      header .results-block.ideal .results .return {
        background-color: #86D73F; }
    header .results-block.ideal h1 {
      color: #86D73F; }
    header .results-block.underweight .results {
      border-color: #31BAF9; }
      header .results-block.underweight .results h1,
      header .results-block.underweight .results p {
        color: #31BAF9; }
      header .results-block.underweight .results .return {
        background-color: #31BAF9; }
    header .results-block.underweight h1 {
      color: #31BAF9; }
    header .results-block.overweight .results {
      border-color: #FF982D; }
      header .results-block.overweight .results h1,
      header .results-block.overweight .results p {
        color: #FF982D; }
      header .results-block.overweight .results .return {
        background-color: #FF982D; }
    header .results-block.overweight h1 {
      color: #FF982D; }
    header .results-block.Mild-obesity .results, header .results-block.Moderate-obesity .results {
      border-color: #FF6C03; }
      header .results-block.Mild-obesity .results h1,
      header .results-block.Mild-obesity .results p, header .results-block.Moderate-obesity .results h1,
      header .results-block.Moderate-obesity .results p {
        color: #FF6C03; }
      header .results-block.Mild-obesity .results .return, header .results-block.Moderate-obesity .results .return {
        background-color: #FF6C03; }
    header .results-block.Mild-obesity h1, header .results-block.Moderate-obesity h1 {
      color: #FF6C03; }
    header .results-block.Severe-obesity .results {
      border-color: #FF1200; }
      header .results-block.Severe-obesity .results h1,
      header .results-block.Severe-obesity .results p {
        color: #FF1200; }
      header .results-block.Severe-obesity .results .return {
        background-color: #FF1200; }
    header .results-block.Severe-obesity h1 {
      color: #FF1200; }

@media (max-width: 992px) {
  header {
    padding: 4.5rem 1rem; }
    header .logo,
    header .submit {
      text-align: center; }
    header .logo {
      padding-bottom: 1rem; }
    header .submit {
      padding-top: 1rem; }
    header .justify-content-responsive {
      -webkit-justify-content: center;
      -moz-justify-content: center;
      -o-flex-justify-content: center;
      -webkit-box-pack: center;
      justify-content: center;
      -ms-flex-pack: center; } }

footer {
  background-color: #FFD366;
  padding: 1rem; }

.main {
  background: #f5f5f5;
  min-height: 50vh; }

.content {
  padding: 3rem 0; }
  .content h2 {
    font-size: 1.5rem;
    color: #424242;
    font-weight: 400;
    text-align: center;
    padding-bottom: 2rem; }
  .content .data-list ul {
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-justify-content: space-between;
    -moz-justify-content: space-between;
    -o-flex-justify-content: space-between;
    -webkit-box-pack: justify;
    justify-content: space-between;
    -ms-flex-pack: justify;
    -webkit-align-items: flex-end;
    align-items: flex-end;
    -webkit-box-align: end;
    -ms-flex-align: end;
    background: #fff;
    border-left: 7px solid;
    padding: 1.4rem;
    margin-bottom: 1rem;
    position: relative; }
    .content .data-list ul::before {
      content: "移除";
      display: block;
      position: absolute;
      font-size: 1.3rem;
      padding: 1.4rem;
      width: calc(100% + 7px);
      height: 100%;
      color: #fff;
      background-color: #424242;
      top: 0;
      left: -7px;
      text-align: center;
      opacity: 0;
      -webkit-transition: all 0.2s;
      -moz-transition: all 0.2s;
      -o-transition: all 0.2s;
      -ms-transform: all 0.2s;
      transition: all 0.2s; }
    .content .data-list ul:hover::before {
      opacity: 1;
      -webkit-transition: all 0.2s;
      -moz-transition: all 0.2s;
      -o-transition: all 0.2s;
      -ms-transform: all 0.2s;
      transition: all 0.2s; }
    .content .data-list ul.ideal {
      border-color: #86D73F; }
    .content .data-list ul.underweight {
      border-color: #31BAF9; }
    .content .data-list ul.overweight {
      border-color: #FF982D; }
    .content .data-list ul.Mild-obesity, .content .data-list ul.Moderate-obesity {
      border-color: #FF6C03; }
    .content .data-list ul.Severe-obesity {
      border-color: #FF1200; }
    .content .data-list ul li {
      font-size: 12px;
      color: #424242; }
      .content .data-list ul li span {
        display: inline-block;
        color: #4A4A4A;
        font-size: 1.3rem;
        padding-left: .5rem; }
      .content .data-list ul li.time {
        padding-bottom: 2px; }

@media (max-width: 576px) {
  .content .data-list ul {
    -webkit-flex-direction: row;
    -moz-flex-direction: row;
    -ms-flex-direction: row;
    -o-flex-direction: row;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    flex-direction: row;
    -webkit-flex-wrap: wrap;
    -moz-flex-wrap: wrap;
    -ms-flex-wrap: wrap;
    -o-flex-wrap: wrap;
    flex-wrap: wrap; }
    .content .data-list ul * {
      -ms-flex: 0 1 auto; }
    .content .data-list ul li {
      width: 100%; }
      .content .data-list ul li .BMI-type {
        padding-left: 0; } }

@-moz-document url-prefix() {}

/*# sourceMappingURL=main.css.map */
              
            
!

JS

              
                var submitBtn = document.querySelector('.submit-btn');
var returnBtn = document.querySelector('.return');
var resultsEl = document.querySelector('.results-block');
var list = document.querySelector('.data-list');
var data = JSON.parse(localStorage.getItem('BMIList')) || [{}];
updateList();
// 判斷BMI值,並顯示於下方清單
function checkBMI(e) {
    e.preventDefault();
    var heightEl = document.getElementById('heightEl');
    var widthEl = document.getElementById('widthEl');
    var num = parseInt(widthEl.value) / ((parseInt(heightEl.value) / 100) * (parseInt(heightEl.value) / 100));
    var results = num.toFixed(1);
    var resultsType = document.querySelector('.results-block>h1');
    var BMIType;
    var BMITypeEn;
    // 取得輸入時的時間
    var d = new Date();
    var getNewDate = (d.getMonth() + 1) + '-' + d.getDate() + '-' + d.getFullYear();
    resultsEl.style.display = 'flex';
    submitBtn.style.display = 'none';
    document.querySelector('.results h1').textContent = results;
    // 判斷BMI值
    if (results >= 18.5 && results < 24) {
        resultsEl.classList.add('ideal');
        resultsType.textContent = '理想';
        BMIType = '理想';
        BMITypeEn = 'ideal';
    } else if (results < 18.5) {
        resultsEl.classList.add('underweight');
        resultsType.textContent = '過輕';
        BMIType = '過輕';
        BMITypeEn = 'underweight';
    } else if (results >= 24 && results < 27) {
        resultsEl.classList.add('overweight');
        resultsType.textContent = '過重';
        BMIType = '過重';
        BMITypeEn = 'overweight';
    } else if (results >= 27 && results < 30) {
        resultsEl.classList.add('Mild-obesity');
        resultsType.textContent = '輕度肥胖';
        BMIType = '輕度肥胖';
        BMITypeEn = 'Mild-obesity';
    } else if (results >= 30 && results < 35) {
        resultsEl.classList.add('Moderate-obesity');
        resultsType.textContent = '中度肥胖';
        BMIType = '中度肥胖';
        BMITypeEn = 'Moderate-obesity';
    } else {
        resultsEl.classList.add('Severe-obesity');
        resultsType.classList.add('Severe-obesity');
        resultsType.textContent = '重度肥胖';
        BMIType = '重度肥胖';
        BMITypeEn = 'Severe-obesity';
    }
    data.push({
        width: parseInt(widthEl.value),
        height: parseInt(heightEl.value),
        BMI: results,
        type: BMIType,
        typeEn: BMITypeEn,
        time: getNewDate
    });
    updateList();
    localStorage.setItem('BMIList',JSON.stringify(data));
}

// 顯示於下方清單
function updateList() {
    var str = '';
    for (var i = 0; i < data.length; i++) {
        str += '<ul class="list-unstyled ' + data[i].typeEn + '" data-num="'+ i +'"><li><span class="BMI-type">' + data[i].type + '</span></li><li>BMI<span class="BMI">' + data[i].BMI + '</span></li><li>weight<span class="weight">' + data[i].width + 'kg</span></li><li><span class="height">' + data[i].height + 'cm</span></li><li class="time">' + data[i].time + '</li></ul>';
    }
    list.innerHTML = str;
}
// 回到檢測按鈕,並清除檢測結果的class
function returnForm() {
    resultsEl.style.display = 'none';
    submitBtn.style.display = 'block';
    resultsEl.classList.remove(resultsEl.classList[1]);
}
// 刪除清單
function deleteList(e){
    e.preventDefault();
    if(e.target.nodeName !== 'UL'){
        return
    }
    var number =e.target.dataset.num;
    data.splice(number,1);
    localStorage.setItem('BMIList',JSON.stringify(data));
    updateList();
}
submitBtn.addEventListener('click', checkBMI, false);
returnBtn.addEventListener('click', returnForm, false);
list.addEventListener('click',deleteList,false);
              
            
!
999px

Console