본문 바로가기

Programming

(69)
The while Loop let rep = 1; while (rep
Looping Arrays, Breaking and Continuing const sunnyArray = [ 'Sunny', 'Ryu', 2022 - 1988, 'technical writer', ['Writing', 'Coding', 'Learning'] ]; for (let i = 0; i < sunnyArray.length; i++) { console.log(sunnyArray[i]); } console.log(sunnyArray[i], typeof sunnyArray[i]); const types = []; for (let i = 0; i < sunnyArray.length; i++) { // Reading from sunny array console.log(sunnyArray[i], typeof sunnyArray[i]); // Filling types array ..
Iteration: The for Loop for (let repetition = 1; repetition
Coding Challenge #3 - comparing BMIs using objects Tried 👏👏👏 const Mark = { fullName: 'Mark Miller', mass: 78, height: 1.69, calcBMI: function () { this.bmi = this.mass / (this.height * this.height); return this.bmi.toFixed([1]); } } const John = { fullName: 'John Smith', mass: 92, height: 1.95, calcBMI: function () { this.bmi = this.mass / (this.height * this.height); return this.bmi.toFixed([1]); } } function compareBmi() { whoHasHigherBmi = M..
Object Methods const sunny = { firstName: 'Sunny', lastName: 'Ryu', birthYear: 1988, job: 'technical writer', hobbies: ['Writing', 'Coding', 'Learning'], hasDriversLicense: true, calcAge: function (birthYear) { return 2022 - birthYear; } }; console.log(sunny.calcAge(1988)); // prints 34 console.log(sunny['calcAge'](1988)); // prints 34 Don't repeat by yourself principle 위에서 보면 birthYear 1988을 2번 이상 반복해서 사용함 근데..
Dot vs. Bracket Notation const sunny = { firstName: 'Sunny', lastName: 'Ryu', age: 2022 - 1988, job: 'technical writer', hobbies: ['Writing', 'Coding', 'Learning'] }; console.log(sunny); 코드에 작성한 property 순서와는 상관없이 automatically ordered됨 참고로 dot notation에서는 real final name이 필요함 e.g.) sunny.'last' + nameKey 🙅‍♀️ console.log(sunny.lastName); console.log(sunny['lastName']); // prints Ryu firstName이랑 lastName에서 Name이 중복되니 na..
Introduction to Objects In JavaScript, an object is an unordered collection of key-value pairs. Each key-value pair is called a property. The key of a property can be a string. And the value of a property can be any value, e.g., a string, a number, an array, and even a function. JavaScript provides you with many ways to create an object. https://www.javascripttutorial.net/javascript-objects/ JavaScript Objects In this ..
Coding Challenge #2 - tip calculator with arrays Tried 👏👏👏 const tips = [125, 555, 44]; const calcTip = function (billValue) { if (billValue >= 50 && billValue = 50 && bill bill >= 50 && billl
Basic Array Operations (Methods) const friends = ['Michael', 'Steven', 'Peter']; friends.push('Jay'); console.log(friends); // prints ['Michael', 'Steven', 'Peter', 'Jay'] Add elements const friends = ['Michael', 'Steven', 'Peter']; const newLength = friends.push('Jay'); console.log(newLength); // prints 4 friends.unshift('John'); console.log(friends); // prints ['John', 'Michael', 'Steven', 'Peter', 'Jay'] unshift() method is ..
Introduction to Arrays const friend1 = 'Michael'; const friend2 = 'Steven'; const friend3 = 'Peter'; const friends = ['Michael', 'Steven', 'Peter']; console.log(friends); const y = new Array(1991, 1984, 2008, 2020); console.log(friends[0]); console.log(friends[2]); console.log(friends.length); console.log(friends[friends.length - 1]); friends[2] = 'Jay'; console.log(friends); const firstName = 'Jonas'; const jonas = [..