Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- </head>
- <body>
- <h1>większe niż 1/mniejsze niż 100/text</h1>
- <input id="numer"> <!-- formularz -->
- <button type="button" onclick="numernietak()">Sprawdź</button> <!-- przycisk -->
- <h1>Liczba losowa</h1>
- <p id="demo"></p>
- <script>
- function numernietak(){
- var x, text;
- x = document.getElementById('numer').value;
- if (isNaN(x) || x < 1 || x > 100){ //sprawdza czy x jest mniejsze niz 100 i wieksze niz 1 oraz czyh nie jset tekstem
- write = "NIE"; //jezeli warunki sie nie zgadzaja pisze NIE
- }
- else{
- write = "TAK"; //jezeli warunki sie zgadzaja pisze TAK
- }
- if (x == "") {
- alert("Pole musi być wypełnione."); //jezeli pole nie jest wypelnione wyskakuje zawiadomienie
- return false;
- }
- document.getElementById("demo").innerHTML = write;
- }
- </script>
- <input id="zgadywana">
- <button type="button" onclick="llosowa()">Losowa</button>
- <script>
- function llosowa(){
- var losowa;
- losowa = Math.floor(Math.random() * 10); //losuje liczbę od 0-9
- var zgd;
- zgd = document.getElementById('zgadywana').value;
- if(losowa == zgd){ //sprawdza poprawność zgadniętej
- document.getElementById("demo").innerHTML = "Zgadłeś"; //poprawna
- }
- else{
- document.getElementById("demo").innerHTML = "Nie zgadłeś wylosowanej liczby, ktora wynosi: " + losowa; //niepoprawna
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement