Call & Apply Method

<script> const airasia = { airline: 'Airasia', iataCode: 'DX', bookings: [], //book: function(){} //New Syntax As Below book(flightNum, name){ console.log(`${name} booked a seat on ${this.airline} flight ${this.iataCode}${flightNum}`); }, }; airasia.book(2678,…

High Order Function

<script> const oneWord = function (str){ return str.replace(/ /g,'').toLowerCase(); }; const upperFirstWord = function (str) { const [first, ...others] = str.split(' '); return [first.toUpperCase(), ...others].join(' '); }; //Higher-Order function const…

Value vs Reference

<script> const flight = 'LH123'; const amanda = { name: 'Amanda Law', passport: 54124092 } const checkIn = function(flightNum, passenger){ flightNum = 'LH999'; passenger.name = 'Mr.' + passenger.name; if(passenger.passport ===…

123. Coding Challenge 4

Working With Strings <script> document.body.append(document.createElement('textarea')); document.body.append(document.createElement('button')); //const text = document.querySelector('textarea').value; document.querySelector('button').addEventListener('click',function(){ const text = document.querySelector('textarea').value; //console.log(text); const rows = text.split('\n'); //先把一整段分成五段 for (const [i, row] of rows.entries()){ const [first, second]…

119. Coding Challenge 3

SetsMaps : FundamentalMaps : Iteration <script> const game = { team1: 'Bayern Munich', team2: 'Borrussia Dortmund', players: [ [ 'Never', 'Pavard', 'Martinez', 'Alaba', 'Davies', 'Kimmich', 'Goretzka', 'Coman', 'Muller', 'Gnarby', 'Lewandowski',…

109. Coding Challenge 1

Destructuring ArraysDestructuring ObjectsSpread Operator Short Circuiting && and ||Nullish Coalescing Operator (??) <script> const game = { team1: 'Bayern Munich', team2: 'Borrussia Dortmund', players: [ [ 'Never', 'Pavard', 'Martinez', 'Alaba',…