분류 전체보기 441

[JS] day11_try~catch

DOCTYPE html> try~catch console.log('프로세스 시작'); try{ alerttt('경고창 실행'); //명령어가 잘못된 부분 console.log('경고창 실행 확인'); }catch(err){ console.log('catch 영역'); console.log(err.name); //에러 이름출력 ReferenceError console.log(err.message); //에러 메세지출력 alerttt is not defined try{ if(err.message.toString().length > 0){ throw 'throw error'; // 무조건 error (err2 catch를 보려고 사용함!) } }catch(err2){ console.log('err2: ',er..

HTML.CSS.JS/JS 2023.04.18

[JS] lotto번호 생성 / 출력 (set, [ ] 이용)

1~45까지의 중복되지 않는 숫자 6개를 랜덤으로 추출 => 출력 (set 객체를 사용) 랜덤번호 6개 생성 및 출력 당첨번호 7개 생성 및 출력 (마지막 번호는 보너스) 결과 확인 다시하기 " data-ke-type="html">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">    titl..

HTML.CSS.JS/JS 2023.04.18

[JS] class 예제 : 은행 (입금, 출금, 이체)

1. let으로 하나씩 만들어 사용하는 경우 let myAccount = { //이름 name: 'hong', //잔액 balance: 0, //입금 deposit: function(amount){ this.balance += amount; }, //출금 withdraw: function(amount){ this.balance -= amount; }, //이체 transfer: function(amount, otherAccount){ this.balance -= amount; otherAccount.balance += amount; } }; let yourAccount = { //이름 name: 'kim', //잔액 balance: 100, //입금 deposit: function(amount){ thi..

HTML.CSS.JS/JS 2023.04.18

[JS] class, 객체, 생성자

class, 객체, 생성자 객체를 생성할 때, 생성자를 넣지 않는 경우 undefined로 출력 객체 생성 후, 객체 설정 추가가능! (굳이 생성자를 자세히 만들 필요 X) 생성자는 자바스크립트 하나에 오직 하나만 허용!! 예시 예) 은행 - 입금/출금/이체 https://jungeun980906.tistory.com/214 예) 생성자 함수이용 클래스 생성 생성 // 클래스생성 class Car{ // 생성자 생성 : 자바스크립트에서는 생성자는 오직 1개! 허용 constructor (name, year){ this.name = name; this.year = year; this.model = ''; } } // 객체생성 let myCar1 = new Car('쏘나타', 2022); let myCar2..

HTML.CSS.JS/JS 2023.04.18

[JS] Map 예제 : 과목, 점수를 map에 저장하고 합계,평균 등 출력

과목 : 점수 : 추가버튼 출력버튼 결과버튼 " data-ke-type="html">HTML 삽입미리보기할 수 없는 소스  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>Map 예제title>            추가버튼 : map에 추가        출력버튼 : map을 출력..

HTML.CSS.JS/JS 2023.04.18