HTML / JS Slot Machine Simulator This code is a slot machine simulator that uses elements of both HTML and JavaScript. Please pardon the lack of comments.

&lt;!DOCTYPE html&gt;
&lt;html&gt;

&lt;head&gt;

&lt;meta charset="utf-8"&gt;
&lt;meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"&gt;
&lt;title&gt;www.loseloselose.com&lt;/title&gt; 
&lt;font color="white"&gt; 

&lt;script&gt;
function Refresh()    
{
if (count &gt; 0)    
{
window.location.reload()
}
}

var sound = new Audio("winner.wav")    
var count = 0   
var one = Math.floor((Math.random()*9)+1)
var two = Math.floor((Math.random()*9)+1)
var three = Math.floor((Math.random()*9)+1)

function countClicks()
{
count = count + 1
document.getElementById("p2").innerHTML = count
}
&lt;/script&gt;

&lt;/head&gt;

&lt;body style="background-color:black;"&gt; 

&lt;center&gt;
&lt;font size="500"&gt;
&lt;font face="arial"&gt;

&lt;p&gt;
Lucky Number Slots
&lt;/p&gt;

&lt;/font&gt;
&lt;/font&gt;
&lt;/center&gt;

&lt;center&gt;
&lt;svg width="550" height="250" viewBox="0 0 1600 500"&gt; 

&lt;rect x="0" y="10" width="500" height="500" fill="black" stroke="white" stroke-width="10"&gt;
&lt;/rect&gt;

&lt;rect x="550" y="10" width="500" height="500" fill="black" stroke="white" stroke-width="10"&gt;
&lt;/rect&gt;

&lt;rect x="1100" y="10" width="500" height="500" fill="black" stroke="white" stroke-width="10"&gt;
&lt;/rect&gt;

&lt;text x="100" y="415" font-family="courier" font-size="500" fill="white"&gt;

&lt;script&gt;  
document.write(one)
&lt;/script&gt;

&lt;/text&gt;

&lt;text x="650" y="415" font-family="courier" font-size="500" fill="white"&gt;

&lt;script&gt;
document.write(two)
&lt;/script&gt;

&lt;/text&gt;

&lt;text x="1200" y="415" font-family="courier" font-size="500" fill="white"&gt;

&lt;script&gt;
document.write(three)
&lt;/script&gt;

&lt;/text&gt;
&lt;/svg&gt;  
&lt;/center&gt;

&lt;center&gt;

&lt;script&gt;
if (one == two &amp;&amp; one == three &amp;&amp; one != null)    
{
document.write("&lt;font face=arial color=white size=50&gt;Winner!&lt;/font&gt;")   
sound.play()        
}
&lt;/script&gt;

&lt;/center&gt;

&lt;form&gt;
&lt;center&gt;

&lt;input type="button" value="Click Here To Spin" onClick="Refresh()"&gt; 

&lt;/center&gt;   
&lt;/form&gt;

&lt;center&gt;

&lt;p&gt;
&lt;a href="javascript:countClicks()"&gt;

&lt;font color="white"&gt;
Add Credit   
&lt;/font&gt;

&lt;/a&gt;
&lt;/p&gt;

&lt;font size="10"&gt;

&lt;p id="p2"&gt;        
0       
&lt;/p&gt;

&lt;/font&gt;    
&lt;/center&gt;  
&lt;/body&gt; 
&lt;/font&gt;
&lt;/html&gt;
Some improvements: 

Use of refresh() as a function used to generate the number values, which generate the values AND writes into the DOM element.

Use of a function to manage all user messages, write_message()

Remove of all the old fashion HTML tags, and change it for CSS.

A function for managing spending the "credits" to make it easier to manage them.

&lt;!DOCTYPE html&gt;
&lt;html&gt;

&lt;head&gt;

    &lt;meta charset="utf-8"&gt;
    &lt;meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"&gt;
    &lt;title&gt;www.loseloselose.com&lt;/title&gt;

    &lt;script&gt;
        var count = 0;
        var sound = new Audio("winner.wav");

        function write_message( $message ) {
            document.getElementById('messages').innerHTML = $message;
        }

        function refresh()
        {
            if ( count &gt; 0 ) {
                refreshCounts(-1);
                var one = Math.floor((Math.random()*9)+1);
                var two = Math.floor((Math.random()*9)+1);
                var three = Math.floor((Math.random()*9)+1);

                document.getElementById('first').innerHTML = one;
                document.getElementById('second').innerHTML = two;
                document.getElementById('third').innerHTML = three;

                if ( one == two &amp;&amp; two == three &amp;&amp; three == one  ) {
                    write_message( 'winner!' );
                } else {
                    write_message( 'wasted try...' );
                }
            } else {
                write_message( 'I need credits to give you fun!' );
            }
        }

        function refreshCounts( value ) {
            count = count + value;
            document.getElementById("p2").innerHTML = count;
        }
    &lt;/script&gt;

    &lt;style&gt;
        body {
            text-align: center;
            background-color: black;
        }

        p, a {
            color: yellow;
            font-weight: 12px;
        }

        .title {
            font-size: 50px;
            text-align: center;
        }

        #machine {
            text-align: center;
        }
    &lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;p class="title"&gt;
    Lucky Number Slots
&lt;/p&gt;


&lt;div id="machine"&gt;
    &lt;svg width="550" height="250" viewBox="0 0 1600 500"&gt;

    &lt;rect x="0" y="10" width="500" height="500" fill="black" stroke="white" stroke-width="10"&gt;
    &lt;/rect&gt;

    &lt;rect x="550" y="10" width="500" height="500" fill="black" stroke="white" stroke-width="10"&gt;
    &lt;/rect&gt;

    &lt;rect x="1100" y="10" width="500" height="500" fill="black" stroke="white" stroke-width="10"&gt;
    &lt;/rect&gt;

    &lt;text x="100" y="415" font-family="courier" font-size="500" fill="white" id="first"&gt;
    0
    &lt;/text&gt;

    &lt;text x="650" y="415" font-family="courier" font-size="500" fill="white" id ="second"&gt;
    0
    &lt;/text&gt;

    &lt;text x="1200" y="415" font-family="courier" font-size="500" fill="white" id="third"&gt;
    0
    &lt;/text&gt;
    &lt;/svg&gt;
&lt;/div&gt;


&lt;p&gt;
    &lt;input type="button" value="Click Here To Spin" onClick="refresh()"&gt;
&lt;/p&gt;

&lt;p&gt;
    &lt;a href="javascript:refreshCounts(+1)"&gt;Add Credit&lt;/a&gt;
&lt;/p&gt;

&lt;p id="p2"&gt;0&lt;/p&gt;

&lt;p id="messages"&gt;&lt;/p&gt;