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..b26b476 100644 --- a/2_solution.js +++ b/2_solution.js @@ -5,7 +5,8 @@ let user = { years: 21, }; -// 여기에 코드를 작성해주세요 +//구조 분해 할당을 이용하여 각각의 프로퍼티 값을 변수에 할당함 +const {name:Name , years:age, isAdmin: isAdmin = false} = user; alert(Name); // "민서" alert(age); // 21 diff --git a/3_solution.js b/3_solution.js index 60fba3a..491d071 100644 --- a/3_solution.js +++ b/3_solution.js @@ -5,4 +5,8 @@ let user = { part: "FE", }; -//답 작성 \ No newline at end of file + const json = JSON.stringify(user); //객체를 JSON 문자열로 변환 + console.log(json) + + const parsed = JSON.parse(json); //JSON 형태를 다시 객체로 변경 + console.log(parsed); \ No newline at end of file diff --git a/4_solution.js b/4_solution.js index dd39a09..317fb01 100644 --- a/4_solution.js +++ b/4_solution.js @@ -5,8 +5,12 @@ class Person { this.name = name; this.hobby = hobby; } - + getPerson() { console.log(`이름: ${this.name}, 취미: ${this.hobby}`); } -} \ No newline at end of file +} + +//person 클래스의 인스턴스 생성하고 이름과 취미를 입력함 +const pepole = new Person ("채부경","유튜브 보기"); +pepole.getPerson() //getPerson 호출하여 출력 \ No newline at end of file diff --git a/5_solution.js b/5_solution.js index 91cb066..20ceb0e 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]; + +//filter를 사용하여 리스트요소를 나머지 연산하여 0인 조건을 만족하는게 여러개여도 전부 출력함 +const filtered = numbers.filter(number => number%2 === 0); +console.log(filtered) //filtered 출력 \ No newline at end of file diff --git a/6_solution.js b/6_solution.js index af7922b..d051f73 100644 --- a/6_solution.js +++ b/6_solution.js @@ -5,20 +5,13 @@ let arr = [ { part: "staff", name: "수빈", age: 24 }, { 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 + + // filtered에 staff와 "보연"을 제외하고 저장 + const filtered = arr.filter(user => user.part !== "staff" && user.name !== "보연"); + filtered.sort((a,b)=> b.age-a.age); //내림차순으로 정렬 + const new_arr = filtered.map(user=>user.name); //이름만 뽑아서 new_arr에 저장 + + console.log("최종 이름 배열:" , new_arr); //new_arr 출력 + + // forEach()를 사용하여 배열의 모든 요소를 하나씩 실행 + new_arr.forEach((user,index)=> {console.log(`${user}`);}); \ No newline at end of file