12. 정수를 입력받아 별찍기 - 직각 이등변 삼각형
Q. 단수(높이)를 입력받아 직각 이등변 삼각형 *기호로 출력하는 프로그램을 작성하세요.
S. HTML5, javascript, JQuery-3.2.1을 사용하여 작성됐습니다.
<!DOCTYPE html> <html lang="ko"> <head> <meta charset="utf-8"> <title>앙큼한유채`s 일상 Story</title> <script src="http://code.jquery.com/jquery-3.2.1.min.js"></script> <style type="text/css"> .btn{width: 190px;height: 30px; border: 1px solid black;margin-top: 10px;text-align: center;line-height: 30px;cursor: pointer;} </style> </head> <body> <div> <span> Q. 단수(높이)를 입력받아 직각 이등변 삼각형 *기호로 출력하는 프로그램을 작성하세요. </span> </div> <div> <span>단수를 입력하세요.</span> <input type="text" id="heightCnt" autocomplete="off"> </div> <div id="result"> </div> <div class="btn" onclick="btn()">결과</div> <script type="text/javascript"> function btn(){ $("#spanResult").remove(); var heightCnt=$("#heightCnt").val(); if(heightCnt==""){ $("#result").append("<span id='spanResult'>단수를 입력하세요.</span>"); $("#heightCnt").focus(); return; } else{ var sumResult=""; for(var height=0; height<heightCnt; height++){ for(var width=0; width<=height; width++){ sumResult+="*"; } sumResult+="<br>"; } $("#result").append("<span id='spanResult'>결과<br>"+sumResult+"</span>"); } } </script> </body> </html>
|