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 6154379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:15:12+00:00 2026-05-23T20:15:12+00:00

<!DOCTYPE html> <html> <head> </head> <body> <hr> <div> <div id=myPos> </div> </div> <hr> <!–Storing

  • 0
      <!DOCTYPE html>
  <html>
 <head>
 </head>
 <body>
 <hr>
 <div>

   <div id="myPos">

 </div>


 </div>

  <hr>
  <!--Storing my array -->
  <div id="myArray">

  </div>

  <br>
  <br/>
  <hr>

   <script type="text/javascript">
   var pos=-1;


   function randomSort(a,b){
return(parseInt(Math.random()*10)%2);
     }

   function roll(){
var myGun = new Array();
myGun[0]="First Slot";
myGun[1]="Second Slot";
myGun[2]="Third Slot";
myGun[3]="Fourth Slot";
myGun[4]="Fifth Slot";
myGun[5]="Sixth Slot";
myGun.sort(randomSort).toString();

document.getElementById("myArray").innerHTML="";



for(i=0;i<myGun.length;i++)
{
    document.getElementById("myArray").innerHTML+=myGun[i]+ "<br>"; 
}

    document.getElementById("myPos").innerHTML= "Position:"+ (pos=-1);
     }

function shot(){

    if(pos<myGun.length)
    {
        document.getElementById("myPos").innerHTML="Position:"+ (pos=pos+1) +"<br/>";


   }
    else
    {
       alert("you loose");
    }
       return pos;
}

     </script>

<footer>
    <button id="btnRoll" onclick="roll()">Roll</button>
    <button id="btnShot" onclick="shot()">Shot</button>
</footer>
    </body>
    </html>
  • 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-05-23T20:15:13+00:00Added an answer on May 23, 2026 at 8:15 pm

    Try this out, it worked for me, but I lost. 🙂 I have fixed several minior bugs and made some adjustments to the HTML, which where not the problem. The problem here was the array – which was local variable to the second function, but not to the third – I have made it golobal variable as pos, but reset it in roll (your original definition looked it should be reset there).

    The first function not need a and b arguments, since it does not use them.
    I have moved all the stuff in the tag of the page, but you can also all script contents it in a separate .js file for readability:
    <script type="text/javascript" src="path to file"></script>.

    Tell me if this work for you, too.

    <!DOCTYPE html>
    <html>
    <head>
        <script type="text/javascript">
            var pos = -1;
            var myGun = new Array;
    
            function randomSort()
            {
                return parseInt(Math.random() * 10) % 2;
            }
    
            function roll()
            {
                myGun = [];
                myGun[0]="First Slot";
                myGun[1]="Second Slot";
                myGun[2]="Third Slot";
                myGun[3]="Fourth Slot";
                myGun[4]="Fifth Slot";
                myGun[5]="Sixth Slot";
                myGun.sort(randomSort).toString();
    
                document.getElementById("myArray").innerHTML = '';
    
    
    
                for(i=0; i < myGun.length; i++)
                    document.getElementById("myArray").innerHTML += myGun[i] + "<br />";
    
                document.getElementById("myPos").innerHTML = "Position:" + (--pos);
            }
    
            function shot()
            {
                if(pos < myGun.length)
                    document.getElementById("myPos").innerHTML = "Position:" + (pos++) + "<br />";
                else
                    alert("you loose");
    
                return pos;
            }
    
         </script>
     </head>
     <body>
        <hr />
        <div>
            <div id="myPos"></div>
        </div>
    
        <hr />
        <!--Storing my array -->
        <div id="myArray">
    
        </div>
    
        <br />
        <br />
    
        <footer>
            <input type="button" id="btnRoll" onclick="roll()" value="Roll" />
            <input type="button" id="btnShot" onclick="shot()" value="Shot" />
        </footer>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<!DOCTYPE html> <html> <head> <title>Test</title> </head> <script type=text/javascript> function fire() { console.log(document.body.children.length); console.log(document.body.children[0].children.length); }
See example: <!DOCTYPE html> <html> <head> <title>language</title> <script type=text/javascript src=http://www.google.com/jsapi> </script> </head> <body> <div
<!DOCTYPE html> <html lang=en> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8> <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js type=text/javascript></script> <script type=text/javascript>
<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN> <html> <head> <style type='text/css'> #body{ margin:0px; }
<!DOCTYPE html> <html> <head> <title>Title</title> <meta http-equiv=content-type content=text/html; charset=utf-8> <style type=text/css> body { background:
I have the following page: <!DOCTYPE html> <html> <head> <style type=text/css> html, body {
Consider this HTML: <!DOCTYPE html> <html> <head> <title></title> <style type=text/css> div { position: relative;
Here's teh codez: <!DOCTYPE html> <html> <head> <title>Test</title> <style type=text/css> html, body { margin:
This is my HTML: <!DOCTYPE html> <html> <head> <script> function run(){ var div =
I have the following code <!DOCTYPE HTML> <html> <head> </head> <body> <div class=full-details-box name=full_details_box

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.