Skills/JavaScript

221108 function.html

개발자 윤구나 2022. 11. 8. 12:09
<!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>
    <script language="javascript">
      function calc(x) {
        let a = 10, b = 5;

        switch (x) {
          case "+":
            return a + b;
          case "-":
            return a - b;
          case "*":
            return a * b;
          case "/":
            return a / b;
        }
      }
    </script>
  </head>
  <body>
    <body>
      <script lanuage="javascript">
        let x, res;
        
        x = prompt("연산자를 입력하세요.");
        res = calc(x);

        document.write(res);
      </script>
    </body>
  </body>
</html>