Skip to content

Instantly share code, notes, and snippets.

View smallpaes's full-sized avatar

Mike Huang smallpaes

View GitHub Profile
@smallpaes
smallpaes / main.js
Last active June 2, 2019 07:21
Get wish list from localStorage and display it
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() {
@smallpaes
smallpaes / main.js
Created June 2, 2019 07:25
Update wish list to localStorage
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
const store = {
name: 'Mr.r Mike Coffee',
employees: 100,
locations: {
taipei: 'Address, Taipei',
singapore: 'Address, Singapore',
sanFrancisco: 'Address, San Francisco'
}
}
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}`)
}
const scores = [100, 90, 95]
const [math, science, history] = scores // math = 100, science = 90, history = 95
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
// 忽略 scores 陣列中 90 這個值
const scores = [100, 90, 95]
const [math, , history] = scores // math: 100, history: 95
const scores = [100, [90, 93], 95]
const [math, [firstHistory, secondHistory]] = scores
console.log(`${math}, ${firstHistory}, ${secondHistory}`) //100, 90, 93
const store = {
name: 'Mr.r Mike Coffee',
employees: 100
}
const { name, employees } = store // name = Mr.r Mike Coffee, employees = 100
const store = {
name: 'Mr.r Mike Coffee',
employees: 100
}
const { name: storeName, employees: employeesNum } = store
console.log(`${storeName}, ${employeesNum}`) //Mr.r Mike, Coffee 100