Beginner in need of help for basic JavaScript game.
Hi all, I'm very new to JavaScript and well, programming in general actually! I've made a small "Name the City" game. So basically when the code is run on the Google Chrome console the game asks the user to choose a country and then asks what the capital city is. It's very basic and I've only added 4 countries and cities. What I would like to happen though is that once the user has played through once, it asks if the player would like to play again and then if Yes is selected it all starts again from the beginning. There are several things I've been playing around with. Maybe I need some sort of function for the "let promptCountry" and "let promptCity". I'm thinking one of the issues is that these are global variables and once the user plays through once is saves their response to each variable. Oh, I'm also aware I should be using arrow functions as per ES6 but for now I was just hoping to get my head around this problem then I'll convert to arrow functions after. I also probably need to wrap the whole thing in a loop but can't quite figure it out. Anyway if anyone could help It would be greatly appreciated. Thanks all! const database = [ {country: "England", city: "London"}, {country: "France", city: "Paris"}, {country: "Germany", city: "Berlin"}, {country: "Spain", city: "Madrid"} ] function check_city(country, city) { for (var i=0; i < database.length; i++) { if (database[i].country === country && database[i].city === city) { return true; } } return false; } function gameResponse(con, cit) { if (check_city(con, cit)) { alert("Well Done"); } else { alert("That is incorrect"); }} function play_again(play_again_response) { if (play_again_response != "Yes") { return("Goodbye"); } else { return("Here I would like the program to start again") } } let promptCountry = prompt("Choose a country"); let promptCity = prompt("What is the city?"); gameResponse(promptCountry, promptCity); let promptPlayAgain = prompt("Do you want to play again? (Ye