Arrays Challenge 4

<script> const dogs = [ {weight: 22, curFood: 250, owners: ['Alice', 'Bob']}, {weight: 8, curFood: 200, owners: ['Matilda']}, {weight: 13, curFood: 275, owners: ['Sarah','John']}, {weight: 32, curFood: 340, owners: ['Michael']}…

Closure

const secureBooking = function () { let passengerCount = 0; return function () { passengerCount++; console.log(`${passengerCount} passengers`); }; }; const booker = secureBooking(); booker(); booker(); booker(); console.dir(booker); /////////////////////////////////////// // More…

134. Coding Challenge 1

<script> document.body.append(document.createElement('button')); const poll = { question: 'What is your favourite programming language?', options: ['0:JavaScript', '1:Phyton', '2:Rust', '3:C++'], answers: new Array(4).fill(0), registerNewAnswer(){ const answer = Number(prompt(`${this.question}\n${this.options.join('\n')}\n(Write option number)`)); //Update answer…

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 ===…