Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9188913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:07:35+00:00 2026-06-17T20:07:35+00:00

I am making a geo quiz with a map. I have this function to

  • 0

I am making a geo quiz with a map. I have this function to load different country names randomly.

<h1>Can you locate

<script type="text/javascript">

generateCountry();


function generateCountry(){

filenames = [ "Greece", "France", "Italy", "United Kingdom", "Germany" ];

filename = filenames[Math.floor(Math.random()*filenames.length)];

document.write(filename);
}


</script>
on the map?
</h1>

and I am using google maps, where when I click the right country with a function I’m getting an alert of whether I was right or wrong.

   function getCountry(latLng) {
              geocoder.geocode( {'latLng': latLng},
                function(results, status) {
                  if(status == google.maps.GeocoderStatus.OK) {
                    if(results[0]) {
                      for(var i = 0; i < results[0].address_components.length; i++) {
                        if(results[0].address_components[i].types[0] == "country") {
                          if(results[0].address_components[i].long_name == filename) {
                              alert("right");

                                generateCountry();

                           } else {
                              alert("wrong");

                           }
                        }
                      }
                    }


                    else {
                      alert("No results");
                    }
                  }
                  else {
                    alert("Status: " + status);
                  }
                }
              );
      }  

when the quiz loads I see the first question for example : Can you locate France on the map?
and the map responds well. When I click the right one, the map after that seems to recognize a new country in the filename variable as when I click on the other countries I finally get a right on Germany for instance. So the map seems to be getting it right. The problem is that the name on the question above doesn’t change from France to Germany. What do I need to do so that after clicking ok on the first question’s right alert a new country name is loaded, without reloading the whole page of course? I know I am probably not using the best way to do it so any help and guidance would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:07:36+00:00Added an answer on June 17, 2026 at 8:07 pm

    Don’t use document.write. Instead, place an empty span in the text and give it an id, like this:

    <h1>Can you locate <span id="country"></span> on the map?</h1>
    

    Then, when you want to change it, get the element using the DOM and change the text:

    document.getElementById('country').textContent = "Germany";
    

    Another benefit of doing it this way is that the script doesn’t have to be in the middle of the h1; you can move it to the head or the end of the body, depending on which you prefer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Making .htaccess (mod_rewrite) work has been very difficult I already have this script for
Making my way through the GAE documents. I have a question I can't find
I have a geo_locations table that looks like this: country | city | postalCode
im making an application where i have to load my database from html file
Making a word document of our network set-up. We have about 7 servers and
Making my first steps in RIA Services (VS2010Beta2) and i encountered this problem: created
making an infinite loop in javascript, and jQuery... this is my current code: $(#bg2).css({opacity:
Making my PHP Command line application support Linux and Windows. Currently it has this
I am trying to do this tutorial https://developers.facebook.com/docs/howtos/login/getting-started/ I have done everything necessary(I think)
Making a simple three question PHP quiz. Each question is displayed on a page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.