Created
January 30, 2017 02:53
-
-
Save Obayanju/07e94d1e5d514fd027335e39f346dc08 to your computer and use it in GitHub Desktop.
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
/* | |
A short game where the player is required to complete the name of a country. Hints are also given. | |
*/ | |
var rightHintCharacterAmount; | |
var leftHintCharacterAmount; | |
var randomNumber; | |
var countryChosen; | |
var countriesArray = [ | |
"Somalia", | |
"Benin", | |
"Slovakia", | |
"Paraguay", | |
"Colombia", | |
"Egypt", | |
"Japan", | |
"Lebanon", | |
"ScotLand", | |
"Bahamas", | |
"Afghanistan" | |
]; | |
var countryHint = [ | |
"A war-torn eastern African country that borders the Gulf of Aden, the Indian Ocean, Ethiopia and Kenya.", | |
"A French speaking West African country", | |
"A central European country known for its dramatic natural landscape and many castles.", | |
"A landlocked country between Argentina, Brazil and Bolivia.", | |
"A country at the northern tip of South America.", | |
"It is one of six civilizations to arise independently", | |
"A island nation in the Pacific Ocean with dense cities, imperial palaces, mountainous national parks and thousands of shrines and temples", | |
"A Middle Eastern country with a history of civil war and political instability, bordering Syria, Israel and the Mediterranean Sea.", | |
"The U.K.’s northernmost country", | |
"A coral-based archipelago in the Atlantic Ocean.", | |
"This country has repeatedly been on the headlines for more than a decade mostly due to terrorism" | |
]; | |
randomNumber = Math.round(Math.random() * 10); //this is so that the random number would be a whole number | |
countryChosen = countriesArray[randomNumber]; | |
function countryGuess(country){ | |
var countryLen = country.length; | |
var hintPosition = Math.round(countryLen / 2); // to get the position of the letter that would be given as a hint | |
var hintcharacter = country.charAt(hintPosition); | |
rightHintCharacterAmount = countryLen - (hintPosition + 1); // this is so we can get the number of characters after the hint character | |
leftHintCharacterAmount = countryLen - (rightHintCharacterAmount + 1); // this is so we can get the number of characters before the hint character | |
var hint = countryHint[randomNumber]; | |
var answer = prompt( | |
"Guess the country: " + | |
leftHintCharacterAmount + | |
" letters + " + hintcharacter + | |
" + " + rightHintCharacterAmount + | |
" letters" + "\n" + "Hint: " | |
+ hint); | |
if ( answer === country){ | |
alert("Yay, you did great"); | |
} else{ | |
alert("Uhh ... NO, The answer is " + country); | |
} | |
} | |
countryGuess(countryChosen); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment