-
JavaScript Function 예제Javascript 2022. 7. 18. 15:50
EX 01. 함수
1-1. 합을 구하는 함수
<!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> </head> <body> <script> let num1 = Number(prompt('1입력')); let num2 = Number(prompt('2입력')); function addNum(num1,num2){ return num1+num2; } alert(addNum(num1,num2)); </script> </body> </html>
1-2. 기호를 입력받아 계단 출력
<!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> </head> <body> <script> let emoji =""; let row = 0; emoji = prompt('기호 입력'); row = parseInt(prompt('몇줄')); function pyramid(emoji,row){ for(let i=0;i<row;i++){ for(let j =0;j<=i;j++){ document.write(emoji); } document.write('<br>'); } } pyramid(emoji,row); </script> </body> </html>
'Javascript' 카테고리의 다른 글
JavaScript DOM 예제 (0) 2022.07.18 JavaScript Object 예제 (0) 2022.07.18 JavaScript Array 예제 (0) 2022.07.18 JavaScript Basic 예제 (0) 2022.07.18 javascript 이론(3) (0) 2022.05.18