Wisielec w JS - po naciśnięciu przycisku nic się nie dzieje

0

Witam. Mam problem z napisaniem wisielca w JavaScript. Ogólnie samą grę mam napisaną gdzie do wprowadzania danych używam okien prompt, jednak lepszą opcją są osobne przyciski. I z tym mam problem. Nie wiem dlaczego po naciśnięciu przycisku nic się nie dzieje, poszczególne funkcje również nie działają chociaż zdają się być poprawnie napisane. Mam nadzieję że ktoś pomoże mi to naprawić. Z góry dzięki :)

<html>
<head>

<script type="text/javascript">
var lista = ['mitsubishi','skoda','bmw','volkswagen','toyota','subaru'];

function restart()
{
	var dozgadniecia2 = lista[Math.floor((Math.random() * 5) + 0)];
	var dozgadniecia = dozgadniecia2.split('');
	var dlugosc = dozgadniecia.length;
	var tabl = [];
	var zgadn = '';
	var proby = 8 - zgadn.length;
	for (i=0;i<dlugosc;i++)
	{
		tabl[i] = '*';
	}
	var tabl2 = tabl.join('');
	rysuj();
}
function zostaw() 
{
	alert("Nie tykaj bo popsujesz !");
}
function rysuj()
{
document.gra.zgadula.value = tabl2;
doument.gra.zgadn.value = zgadn;
}
function litera(literka)
{
zgadn = zgadn + literka;
if(dozgadniecia.indexOf(literka) != -1)
{	
	for(x=0;x<dlugosc;x++)
	{
		if(dozgadniecia2.charAt(x) == literka)
		{
			tabl[x] = literka;
		}
		else if(dozgadniecia2.charAt(x) != literka)
		{
			tabl[x] = '*';
		}
	}
	tabl2 = tabl.join('');
	rysuj();
}
else
{
	alert("Pudło");
	rysuj();
}
} 

</script>
</head>
<body>
<form id="gra">
<h1>Wisielec</h1>
<input type="text" class="pole" id="zgadula" onclick="zostaw()"> Slowo do zgadniecia<br>
<input type="text" class="pole" id="zgadn" onclick="zostaw()"> Litery podane do tej pory<br>
</form>
<p>Wybierz literke</p>
<button type="button" onclick="litera('a')">A</button>
<button type="button" onclick="litera('b')">B</button>
<button type="button" onclick="litera('c')">C</button>
<button type="button" onclick="litera('d')">D</button>
<button type="button" onclick="litera('e')">E</button>
<button type="button" onclick="litera('f')">F</button>
<button type="button" onclick="litera('g')">G</button>
<button type="button" onclick="litera('h')">H</button>
<button type="button" onclick="litera('')">I</button>
<button type="button" onclick="litera('j')">J</button>
<button type="button" onclick="litera('k')">K</button>
<button type="button" onclick="litera('l')">L</button></br>
<button type="button" onclick="litera('m')">M</button>
<button type="button" onclick="litera('n')">N</button>
<button type="button" onclick="litera('o')">O</button>
<button type="button" onclick="litera('p')">P</button>
<button type="button" onclick="litera('r')">R</button>
<button type="button" onclick="litera('s')">S</button>
<button type="button" onclick="litera('t')">T</button>
<button type="button" onclick="litera('u')">U</button>
<button type="button" onclick="litera('v')">V</button>
<button type="button" onclick="litera('w')">W</button>
<button type="button" onclick="litera('y')">Y</button>
<button type="button" onclick="litera('z')">Z</button></br>
<button type="button" onclick="restart()">RESTART</button>
</body>
</html>

dodanie znaczników <code class="html"> - @furious programming

1

<html>
<head>
<script type="text/javascript">
var lista = ['mitsubishi','skoda','bmw','volkswagen','toyota','subaru'];
 
function restart()
{
    dozgadniecia2 = lista[Math.floor((Math.random() * 5) + 0)];
     dozgadniecia = dozgadniecia2.split('');
     dlugosc = dozgadniecia.length;
     tabl = [];
     zgadn = '';
     proby = 8 - zgadn.length;
    for (i=0;i<dlugosc;i++)
    {
        tabl[i] = '*';
    }
    tabl2 = tabl.join('');
    rysuj();
}
function zostaw() 
{
    alert("Nie tykaj bo popsujesz !");
}
function rysuj()
{
document.getElementById('zgadula').value = tabl2;
document.getElementById('zgadn').value = zgadn;
}
function litera(literka)
{
zgadn = zgadn + literka;
if(dozgadniecia.indexOf(literka) != -1)
{    
    for(x=0;x<dlugosc;x++)
    {
        if(dozgadniecia2.charAt(x) == literka)
        {
            tabl[x] = literka;
        }
        else if(dozgadniecia2.charAt(x) != literka)
        {
			if (tabl2.charAt(x) != '*') {
				tabl[x] = tabl2.charAt(x);
			} else {
				tabl[x] = '*';
			}
        }
    }
    tabl2 = tabl.join('');
    rysuj();
}
else
{
    alert("Pudło");
    rysuj();
}
} 

</script>
</head>
<body onload="restart()">
<form id="gra">
<h1>Wisielec</h1>
<input type="text" class="pole" id="zgadula" onclick="zostaw()"> Slowo do zgadniecia<br>
<input type="text" class="pole" id="zgadn" onclick="zostaw()"> Litery podane do tej pory<br>
</form>
<p>Wybierz literke</p>
<button type="button" onclick="litera('a')">A</button>
<button type="button" onclick="litera('b')">B</button>
<button type="button" onclick="litera('c')">C</button>
<button type="button" onclick="litera('d')">D</button>
<button type="button" onclick="litera('e')">E</button>
<button type="button" onclick="litera('f')">F</button>
<button type="button" onclick="litera('g')">G</button>
<button type="button" onclick="litera('h')">H</button>
<button type="button" onclick="litera('')">I</button>
<button type="button" onclick="litera('j')">J</button>
<button type="button" onclick="litera('k')">K</button>
<button type="button" onclick="litera('l')">L</button></br>
<button type="button" onclick="litera('m')">M</button>
<button type="button" onclick="litera('n')">N</button>
<button type="button" onclick="litera('o')">O</button>
<button type="button" onclick="litera('p')">P</button>
<button type="button" onclick="litera('r')">R</button>
<button type="button" onclick="litera('s')">S</button>
<button type="button" onclick="litera('t')">T</button>
<button type="button" onclick="litera('u')">U</button>
<button type="button" onclick="litera('v')">V</button>
<button type="button" onclick="litera('w')">W</button>
<button type="button" onclick="litera('y')">Y</button>
<button type="button" onclick="litera('z')">Z</button></br>
<button type="button" onclick="restart()">RESTART</button>
</body>
</html>

dodanie znaczników <code class="html"> i <code class="javascript"> - @furious programming

0

Dzięki :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1