Last active
August 29, 2015 13:56
-
-
Save Nnubes256/8806787 to your computer and use it in GitHub Desktop.
Small javascript snippet that asks you the capital of an European country throught a prompt and says if you answered correctly or not every time it's executed. It's in Spanish, traductions welcome. It uses a Key-Value structure to store the countries and its capitals, respectively, includes a null check and LoWeR-uPpEr case support.
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
var capitalList = [ | |
{"K":"Albania","V":"Tirana"}, | |
{"K":"Alemania","V":"Berlín"}, | |
{"K":"Andorra","V":"Andorra la Vella"}, | |
{"K":"Armenia","V":"Ereván"}, | |
{"K":"Austria","V":"Viena"}, | |
{"K":"azerbaiyán","V":"bakú"}, | |
{"K":"Bélgica","V":"Bruselas"}, | |
{"K":"Bielorrusia","V":"Minsk"}, | |
{"K":"Bosnia y Herzegovina","V":"Sarajevo"}, | |
{"K":"Bulgaria","V":"Sofía"}, | |
{"K":"República Checa","V":"Praga"}, | |
{"K":"Croacia","V":"Zagreb"}, | |
{"K":"Dinamarca","V":"Copenhague"}, | |
{"K":"Eslovaquia","V":"Bratislava"}, | |
{"K":"Eslovenia","V":"Liubliana"}, | |
{"K":"España","V":"Madrid"}, | |
{"K":"Estonia","V":"Tallín"}, | |
{"K":"Finlandia","V":"Helsinki"}, | |
{"K":"Francia","V":"París"}, | |
{"K":"Georgia","V":"Tiflis"}, | |
{"K":"Grecia","V":"Atenas"}, | |
{"K":"Hungría","V":"Budapest"}, | |
{"K":"Irlanda","V":"Dublín"}, | |
{"K":"Islandia","V":"Reikiavik"}, | |
{"K":"Italia","V":"Roma"}, | |
{"K":"Letonia","V":"Riga"}, | |
{"K":"Liechtenstein","V":"Vaduz"}, | |
{"K":"Lituania","V":"Vilna"}, | |
{"K":"Luxemburgo","V":"Luxemburgo"}, | |
{"K":"República de Macedonia","V":"Skopje"}, | |
{"K":"Malta","V":"La Valeta"}, | |
{"K":"Moldavia","V":"Chisinau"}, | |
{"K":"Mónaco","V":"Mónaco"}, | |
{"K":"Montenegro","V":"Podgorica"}, | |
{"K":"Noruega","V":"Oslo"}, | |
{"K":"Países Bajos","V":"Amsterdam"}, | |
{"K":"Polonia","V":"Varsovia"}, | |
{"K":"Portugal","V":"Lisboa"}, | |
{"K":"Reino Unido","V":"Londres"}, | |
{"K":"Rumania","V":"Bucarest"}, | |
{"K":"Rusia","V":"Moscú"}, | |
{"K":"San Marino","V":"Ciudad de San Marino"}, | |
{"K":"Serbia","V":"Belgrado"}, | |
{"K":"Suecia","V":"Estocolmo"}, | |
{"K":"Suiza","V":"Berna"}, | |
{"K":"Ucrania","V":"Kiev"}, | |
{"K":"Vaticano","V":"Ciudad del Vaticano"} | |
]; | |
var randomCountryObject = capitalList[Math.floor(Math.random() * capitalList.length)]; | |
var answer = prompt("Dí la capital de " + randomCountryObject.K); | |
if(!answer){ | |
console.log("¡No contestaste weeeey!"); | |
} else if(answer.toLowerCase() == randomCountryObject.V.toLowerCase()) { | |
console.log("¡Coooooorrectoooo!"); | |
} else { | |
console.log("¡Incorreeeeectooo! La respuesta era " + randomCountryObject.V); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment