Programming (69) 썸네일형 리스트형 Coding Challenge #3 - Compare the team's average scores using if / else statements const averageScoreOfDolphins = ((96 + 108 + 89) / 3).toFixed([1]); const averageScoreOfKoalas = ((88 + 91 + 110) / 3).toFixed([1]); console.log(`The average score of Dolphis is ${averageScoreOfDolphins} and the average score of Koalas is ${averageScoreOfKoalas}`); // prints The average score of Dolphis is 97.7 and the average score of Koalas is 96.3 if (averageScoreOfDolphins > averageScoreOfKoa.. The switch Statement const day = 'monday'; switch (day) { case 'monday': // day === 'monday' console.log('월요일병 물리치쟈!'); break; case 'tuesday': console.log('화요일이다!'); break; case 'wednesday': case 'thursday': console.log('Write code examples'); break; case 'friday': console.log('오예 금요일'); break; case 'saturday': case 'sunday': console.log('주말 잘 보내세요 :)'); break; default: console.log('Not a valid day!'); } 여기서 break;를.. Truthy and Falsy Values 5 falsy values: 0, '', undefined, null, NaN console.log(Boolean(0)); // prints false console.log(Boolean(undefined)); // prints false console.log(Boolean('Jonas')); // prints true console.log(Boolean({})); // prints true console.log(Boolean('')); // prints false 0은 Falsy Value이기 때문에- else 문이 실행됨 const money = 0; if (money) { console.log("Don't spend it all"); } else { console.log("나가서 돈을 벌어오쟈");.. Type Conversion and Coercion Type Conversion은 manually convert함 Coercion은 자바스크립에서 자동으로 변환해줌 Type Conversion const inputYear = '1991'; console.log(inputYear + 18); // prints 199118 inputYear가 string이기 때문에 그대로 이어 붙여서 199118이 콘솔에 찍힘 참고로 Type Conversion할 때 Number 첫 글자 대문자로 해줘야 함 const inputYear = '1991'; console.log(Number(inputYear), inputYear); // prints 1991 '1991' console.log(Number(inputYear) + 9); // 2000 참고로 데이터 타입에 따라 콘.. Coding Challenge #2 - BMI Comparison using if / else statements const massMark = 78; const heightMark = 1.69; const massJohn = 92; const heightJohn = 1.95; const BMIMark = (massMark / heightMark ** 2).toFixed([1]); const BMIJohn = (massJohn / (heightJohn * heightJohn)).toFixed([1]); const markHigherBMI = BMIMark > BMIJohn; // BMIMark > BMIJohn if (markHigherBMI) { console.log(`Mark's BMI (${BMIMark}) is higher than John's (${BMIJohn})!`) } else { console.log.. Taking Decisions: if / else Statements const age = 19; const isOldEnough = age >= 18; if (isOldEnough) { console.log('Sunny can start driving license'); } // prints Sunny can start driving license const age = 15; if (age >= 18) { console.log('Sunny can start driving license'); } else { const yearsLeft = 18 - age; console.log(`Sunny is too young. Wait another ${yearsLeft} years :)`); } // prints Sunny is too young. Wait another 3 year.. Strings and Template Literals JavaScript ES6 기준 const firstName = 'Sunny'; const job = 'technical writer'; const birthYear = 1988; const year = 2022; const sunny = "'I'm " + firstName + ', a ' + (year - birthYear) + ' years old ' + job + '!'; console.log(sunny); // print 'I'm Sunny, a 34 years old technical writer! 그런데 위에서 불편한 점은 스페이스 바를 매번 manually 한칸씩 해줘야 함 똑같은 결과가 나오되 자동으로 스페이스바 넣어주려면? const sunnyNew = `I'm ${firstName}, .. Coding Challenge #1 - BMI Comparison Tried let markWeights = 78 let markHeight = 1.69 let johnWeights = 92 let johnHeight = 1.95 let markBMI = markWeights / markHeight ** 2 let johnBMI = johnWeights / (johnHeight * johnHeight) let markHigherBMI = markBMI > johnBMI console.log("Mark's BMI is" + ' ' + markBMI); // Mark's BMI is 27.309968138370508 console.log("John's BMI is" + ' ' + johnBMI); // John's BMI is 24.194608809993426 consol.. Operator Precedence console.log(now - 1991 > now - 2019); // print true as now is 2037 여기서 하나의 궁금증이라면 어떻게 javascript에서는 -와 > 연산의 우선순위를 구분하는가? 고럼 밑에 링크를 들어가보자. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#table Operator precedence - JavaScript | MDN Operator precedence determines how operators are parsed concerning each other. Operators with higher precedence become.. Basic Operators Math operators const ageJonas = 2037 - 1991; console.log(ageJonas); // print 46 const 값 여러 개 출력 원하면 , 컴마로 연달아 적어주면 됨 const ageJonas = 2037 - 1991; const ageSarah = 2037 - 2018; console.log(ageJonas, ageSarah); // print 46 19 여기서 2037을 반복해서 쓰는 것보단 const로 선언해주는 게 나음 const now = 2037 const ageJonas = now - 1991; const ageSarah = now - 2018; console.log(ageJonas, ageSarah); // print 46 19 결과는 위와 동일함.. 이전 1 2 3 4 5 6 7 다음