This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wishList = JSON.parse(localStorage.getItem('wishList')) || [] | |
//display each wish on the wish list | |
function displayWish(input) { | |
displayArea.innerHTML += ` | |
<li>${input}<span>X</span></li> | |
` | |
} | |
function displayWishList() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wishList = JSON.parse(localStorage.getItem('wishList')) || [] | |
function updateLocalStorage() { | |
//store the list back to localStorage | |
localStorage.setItem('wishList', JSON.stringify(wishList)) | |
} | |
//add event listener to form | |
form.addEventListener('submit', event => { | |
//prevent auto send the form |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const store = { | |
name: 'Mr.r Mike Coffee', | |
employees: 100, | |
locations: { | |
taipei: 'Address, Taipei', | |
singapore: 'Address, Singapore', | |
sanFrancisco: 'Address, San Francisco' | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function displayStoreInfo({ name, employees, locations: { taipei, singapore, sanFrancisco } }) { | |
console.log(`You are looking for: ${name}`) | |
console.log(`It currently has ${employees} employees`) | |
console.log(`Location in Taipei: ${taipei}`) | |
console.log(`Location in Singapore: ${singapore}`) | |
console.log(`Location in San francisco: ${sanFrancisco}`) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const scores = [100, 90, 95] | |
const [math, science, history] = scores // math = 100, science = 90, history = 95 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let lunch = 'Beef Noodle' | |
let dinner = 'Chicken Curry Rice' | |
let raining = true | |
if (raining) { | |
// 變數交換 | |
[dinner, lunch] = [lunch, dinner] | |
} | |
console.log(`${lunch} -> ${dinner}`) //Chicken Curry Rice -> Beef Noodle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 忽略 scores 陣列中 90 這個值 | |
const scores = [100, 90, 95] | |
const [math, , history] = scores // math: 100, history: 95 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const scores = [100, [90, 93], 95] | |
const [math, [firstHistory, secondHistory]] = scores | |
console.log(`${math}, ${firstHistory}, ${secondHistory}`) //100, 90, 93 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const store = { | |
name: 'Mr.r Mike Coffee', | |
employees: 100 | |
} | |
const { name, employees } = store // name = Mr.r Mike Coffee, employees = 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const store = { | |
name: 'Mr.r Mike Coffee', | |
employees: 100 | |
} | |
const { name: storeName, employees: employeesNum } = store | |
console.log(`${storeName}, ${employeesNum}`) //Mr.r Mike, Coffee 100 |
OlderNewer