From 1022c050a485f25bc4f776e45eb54acda81484f1 Mon Sep 17 00:00:00 2001 From: BBoyeon <2boyeon2@gmail.com> Date: Sun, 6 Apr 2025 00:16:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?4/3=20=EC=9D=B4=EB=B3=B4=EC=97=B0=20?= =?UTF-8?q?=EA=B3=BC=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_solution.js | 8 ++++---- 2_solution.js | 8 ++++++-- 3_solution.js | 5 ++++- 4_solution.js | 5 ++++- 5_solution.js | 6 +++++- 6_solution.js | 32 ++++++++++++++++---------------- index.html | 7 ++----- 7 files changed, 41 insertions(+), 30 deletions(-) diff --git a/1_solution.js b/1_solution.js index 2d1ddc3..2b2255c 100644 --- a/1_solution.js +++ b/1_solution.js @@ -4,7 +4,7 @@ let name = "신석"; // ? 부분에 예측 값을 작성해주세요(코드 실행 금지) -alert(`hello ${1}`); // ? -alert(`hello ${"name"}`); // ? -alert("hello ${name}"); // ? -alert(`hello ${name}`); // ? \ No newline at end of file +alert(`hello ${1}`); // hello 1 +alert(`hello ${"name"}`); // hello name +alert("hello ${name}"); // hello ${name} +alert(`hello ${name}`); // hello 신석 \ No newline at end of file diff --git a/2_solution.js b/2_solution.js index e5b5e37..ca64839 100644 --- a/2_solution.js +++ b/2_solution.js @@ -5,8 +5,12 @@ let user = { years: 21, }; -// 여기에 코드를 작성해주세요 +const {name : Name, years : age, isAdmin : isAdmin = false} = user; alert(Name); // "민서" alert(age); // 21 -alert(isAdmin); // false \ No newline at end of file +alert(isAdmin); // false + +// console.log(Name); +// console.log(age); +// console.log(isAdmin); \ No newline at end of file diff --git a/3_solution.js b/3_solution.js index 60fba3a..2577960 100644 --- a/3_solution.js +++ b/3_solution.js @@ -5,4 +5,7 @@ let user = { part: "FE", }; -//답 작성 \ No newline at end of file +//답 작성 +const json = JSON.stringify(user); + +console.log(json); \ No newline at end of file diff --git a/4_solution.js b/4_solution.js index dd39a09..0ec9dac 100644 --- a/4_solution.js +++ b/4_solution.js @@ -9,4 +9,7 @@ class Person { getPerson() { console.log(`이름: ${this.name}, 취미: ${this.hobby}`); } -} \ No newline at end of file +} + +const boyeon = new Person("보연", "영화 감상"); +boyeon.getPerson(); \ No newline at end of file diff --git a/5_solution.js b/5_solution.js index 91cb066..938d970 100644 --- a/5_solution.js +++ b/5_solution.js @@ -1,3 +1,7 @@ //5번 문제 -const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; \ No newline at end of file +const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + +const evennum = numbers.filter(num => num % 2 === 0); + +console.log(evennum); diff --git a/6_solution.js b/6_solution.js index af7922b..1d8845d 100644 --- a/6_solution.js +++ b/6_solution.js @@ -6,19 +6,19 @@ let arr = [ { part: "be", name: "기현", age: 25 } ]; - // 1. staff 제거 - arr = arr.filter(member => member.part !== "staff"); - - // 2. "fe"는 남기되 "보연"은 제거 - arr = arr.filter(member => !(member.part === "fe" && member.name === "보연")); - - // 3. 나이 내림차순 정렬 - arr.sort((a, b) => b.age - a.age); - - // 4. 이름만 뽑아 배열 만들기 - const names = arr.map(member => member.name); - console.log("최종 이름 배열:", names); - - // 5. 이름 한 줄씩 출력 - names.forEach(name => console.log(name)); - \ No newline at end of file + +const filtered = arr.filter(user => user.part !== "staff" && user.name !== "보연"); +// staff, "보연" 동시에 제외 + +filtered.sort((a,b) => b.age - a.age); +// 내림차순 정렬 +// a가 크면 음수, b가 크면 양수가 나오므로 큰 수인 b가 앞으로 가게 됨 + +const newarr = filtered.map(user => user.name); +// newarr 라는 이름으로 이름만 뽑아낸 새 배열 저장장 + +console.log("최종 이름 배열 :", newarr); +// 출력 + +newarr.forEach(name => console.log(name)); +// forEach를 사용하여 한 줄씩 이름을 출력함 \ No newline at end of file diff --git a/index.html b/index.html index 76932b3..84d34b2 100644 --- a/index.html +++ b/index.html @@ -5,11 +5,8 @@

콘솔 확인용!

- + - - - - + From 15f741308efd35d834dc5a51027411ab5e444fba Mon Sep 17 00:00:00 2001 From: BBoyeon <2boyeon2@gmail.com> Date: Sun, 6 Apr 2025 00:29:28 +0900 Subject: [PATCH 2/2] =?UTF-8?q?4/3=20=EA=B3=BC=EC=A0=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=B3=B4=EC=97=B0=EC=B5=9C=EC=A2=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_solution.js | 8 ++++---- 2_solution.js | 2 ++ 4_solution.js | 5 ++++- 5_solution.js | 3 +++ 6_solution.js | 10 +++++----- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/1_solution.js b/1_solution.js index 2b2255c..d3d8357 100644 --- a/1_solution.js +++ b/1_solution.js @@ -4,7 +4,7 @@ let name = "신석"; // ? 부분에 예측 값을 작성해주세요(코드 실행 금지) -alert(`hello ${1}`); // hello 1 -alert(`hello ${"name"}`); // hello name -alert("hello ${name}"); // hello ${name} -alert(`hello ${name}`); // hello 신석 \ No newline at end of file +alert(`hello ${1}`); // hello 1 -> ${}' 중괄호 안에 1이 들어있으므로 1이 출력됨 +alert(`hello ${"name"}`); // hello name -> ${}' 가 제대로 들어있지만, 중괄호 안에 있는 name이 "신석"을 가리키는 것이 아니라 "name"이라는 문자를 가리키므로 name이 출력됨 +alert("hello ${name}"); // hello ${name} -> 전체가 큰따옴표 안에 들어있으니까 그대로 출력됨 +alert(`hello ${name}`); // hello 신석 -> ${}'의 중괄호 안에 name이 정상적으로 들어있음. name에 저장된 "신석"이 출력됨 \ No newline at end of file diff --git a/2_solution.js b/2_solution.js index ca64839..f8ba75a 100644 --- a/2_solution.js +++ b/2_solution.js @@ -6,6 +6,8 @@ let user = { }; const {name : Name, years : age, isAdmin : isAdmin = false} = user; +// name -> Name으로, years -> age로, isAdmin은 user 배열에 들어있지 않으므로 isAdmin으로 이름 지어줌. +// 문제에서 isAdmin이라는 프로퍼티가 없으면 false를 할당하라고 하였으므로 false 할당 alert(Name); // "민서" alert(age); // 21 diff --git a/4_solution.js b/4_solution.js index 0ec9dac..d142e65 100644 --- a/4_solution.js +++ b/4_solution.js @@ -12,4 +12,7 @@ class Person { } const boyeon = new Person("보연", "영화 감상"); -boyeon.getPerson(); \ No newline at end of file +// "boyeon"이라는 새로운 사람을 정의, Person class를 이용하여 순서대로 이름, 취미를 작성함. + +boyeon.getPerson(); +// 출력. \ No newline at end of file diff --git a/5_solution.js b/5_solution.js index 938d970..618094a 100644 --- a/5_solution.js +++ b/5_solution.js @@ -3,5 +3,8 @@ const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; const evennum = numbers.filter(num => num % 2 === 0); +// 짝수 배열을 새롭게 정의. numbers 배열에 필터를 사용하여 배열 안의 요소들을 num으로 정의. +// num을 2로 나누었을 때 나머지가 0이 되면 새로운 배열인 evennum에 들어가게 함. console.log(evennum); +// 출력. \ No newline at end of file diff --git a/6_solution.js b/6_solution.js index 1d8845d..93e8049 100644 --- a/6_solution.js +++ b/6_solution.js @@ -8,17 +8,17 @@ let arr = [ const filtered = arr.filter(user => user.part !== "staff" && user.name !== "보연"); -// staff, "보연" 동시에 제외 +// staff, "보연" 동시에 제외. 때문에 fe 중에서도 수진, 병윤이 남고 be가 남게 됨. filtered.sort((a,b) => b.age - a.age); // 내림차순 정렬 -// a가 크면 음수, b가 크면 양수가 나오므로 큰 수인 b가 앞으로 가게 됨 +// a가 크면 음수, b가 크면 양수가 나오므로 큰 수인 b가 앞으로 가게 됨. const newarr = filtered.map(user => user.name); -// newarr 라는 이름으로 이름만 뽑아낸 새 배열 저장장 +// newarr 라는 이름으로 이름만 뽑아낸 새 배열 저장. console.log("최종 이름 배열 :", newarr); -// 출력 +// 출력. newarr.forEach(name => console.log(name)); -// forEach를 사용하여 한 줄씩 이름을 출력함 \ No newline at end of file +// forEach를 사용하여 한 줄씩 이름을 출력함. \ No newline at end of file