ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 실습 - 책읽기 날짜 프로그램 만들기
    JavaScript/실습 2023. 1. 24. 13:59

    나의풀이 

     

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
      <style>
        div {
            background-color: blue;
            width:300px;
            height:300px;
            /* border-radius를 반드시 width와 height의 절반으로 해야한다는 점 */
            border-radius: 50%;   
            text-align:center;
            font-size:30px;
            border: solid 1px;  
            position:relative;   
          }     
    
        #text{
          position:absolute;
          top:70px;
          left:100px;
          
        }  
        #contents{
          position:absolute;
          bottom:100px;
          left: 50px;
          font-size:15px; 
        }
       
      </style>  
    </head>
    <body>
    <div>
      <p id="text">책읽기</p>
      <p id="contents"></div>
      <script>
        const date1 = new Date(2020,7,1)
        const date2 = new Date(2020,7,10)
    
        const lapse = date2.getTime() - date1.getTime(); 
        const lapse_day = lapse / 1000 / 60 / 60 / 24; 
        document.querySelector('#contents').textContent = lapse_day + "일 경과 하였습니다";
      </script>    
    </div>
    </body>
    </html>

     

     

    해설풀이 

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
      <style>
        #container{
          margin:auto;
          width:300px;
          height:300px;
          border-radius:50%;
          border: double 2px #222; 
          background-color: whitesmoke;
          text-align:center; 
        }
       
        h1{
          margin-top:80px;
        }
    
        .accent {
          font-size: 1.8em; 
          font-weight: bold;
          color:red;
        }
      </style>  
    </head>
    <body>
    <div>
      <div id="container"> 
        <h1>책 읽기</h1>
        <p><span class="accent" id="result"></span>일 연속으로 <br>책 읽기를 달성했군요</p>
        <p>축하합니다</p>  
      </div>  
      <script>
        var now = new Date('2022-10-15'); 
        var firstDay = new Date('2022-10-01'); 
    
        var toNow = now.getTime(); 
        var toFirst = firstDay.getTime(); 
        var passTime = toNow - toFirst;   
    
        passTime = Math.round(passTime/(1000 * 60 * 60 *24)); 
        
        document.querySelector('#result').innerText = passTime;
         
    
      
      </script>   
    </div>
    </body>
    </html>

    댓글

Designed by Tistory.