This file contains hidden or 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 getPokemon(type) { | |
let pokemon; | |
switch (type) { | |
case 'Water': | |
pokemon = 'Squirtle'; | |
break; | |
case 'Fire': | |
pokemon = 'Charmander'; | |
break; | |
case 'Plant': |
This file contains hidden or 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 pokemon = { | |
Water: 'Squirtle', | |
Fire: 'Charmander', | |
Plant: 'Bulbasur', | |
Electric: 'Pikachu' | |
}; | |
function getPokemon(type) { | |
return pokemon[type] || 'Mew'; | |
} |
This file contains hidden or 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 pokemon = new Map([ | |
['Water', 'Squirtle'], | |
['Fire', 'Charmander'], | |
['Plant', 'Bulbasur'], | |
['Electric', 'Pikachu'] | |
]); | |
function getPokemon(type) { | |
return pokemon.get(type) || 'Mew'; | |
} |
This file contains hidden or 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 checkGameStatus() { | |
if ( | |
remaining === 0 || | |
(remaining === 1 && remainingPlayers === 1) || | |
remainingPlayers === 0 | |
) { | |
quitGame(); | |
} | |
} |
This file contains hidden or 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 isGameLost() { | |
return ( | |
remaining === 0 || | |
(remaining === 1 && remainingPlayers === 1) || | |
remainingPlayers === 0 | |
); | |
} | |
// Our function is now much easier to understand: | |
function checkGameStatus() { |
This file contains hidden or 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 getJavascriptNews() { | |
const allNews = getNewsFromWeb(); | |
const news = []; | |
for (let i = allNews.length - 1; i >= 0; i--){ | |
if (allNews[i].type === "javascript") { | |
news.push(allNews[i]); | |
} | |
} | |
This file contains hidden or 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 getJavascriptNews() { | |
const allNews = getNewsFromWeb(); | |
return getNewsContent(allNews, 'javascript'); | |
} | |
function getRustNews() { | |
const allNews = getNewsFromWeb(); | |
return getNewsContent(allNews, 'rust'); | |
} |
This file contains hidden or 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 getNews(type) { | |
const allNews = getNewsFromWeb(); | |
return getNewsContent(allNews, type); | |
} | |
function getNewsContent(newsList, type) { | |
const news = []; | |
for (let i = newsList.length - 1; i >= 0; i--) { | |
if (newsList[i].type === type) { | |
news.push(newsList[i].content); |
This file contains hidden or 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 getNews(type) { | |
const allNews = getNewsFromWeb(); | |
return getNewsContent(allNews, type); | |
} | |
function getNewsContent(newsList, type) { | |
return newsList | |
.filter(newsItem => newsItem.type === type) | |
.map(newsItem => newsItem.content); | |
} |
This file contains hidden or 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 startProgram() { | |
if (!window.indexedDB) { | |
window.alert("Browser not support indexeDB"); | |
} else { | |
let openRequest = indexedDB.open("store", 1); | |
openRequest.onupgradeneeded = () => {}; | |
openRequest.onerror = () => { | |
console.error("Error", openRequest.error); |