Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function przyciskMenu()
- {
- document.write("<br/>");
- var button = document.createElement("button");
- button.innerHTML = "PowrĂłt do menu";
- button.setAttribute("onclick","menu()");
- var body = document.getElementsByTagName("body")[0];
- body.appendChild(button);
- }
- function menu(){
- document.body.innerHTML = '';
- document.write("<ol><li>Wylicz sumÄ z n-dowolnych liczb</li>");
- document.write("<li>Wylicz ĹredniÄ z liczb parzystych</li>");
- document.write("<li>SprawdĹş czy wprowadzone liczby sÄ liczbami pitagorejskimi")
- document.write("<li>SprawdĹş czy liczba jest pierwsza</li></ol><br/>")
- var button = document.createElement("button");
- button.innerHTML = "WybĂłr";
- button.setAttribute("onclick","wybor()");
- var body = document.getElementsByTagName("body")[0];
- body.appendChild(button);
- }
- function suma()
- {
- let x = prompt("Podaj iloĹÄ liczb");
- let ilosc = parseInt(x);
- let suma = 0;
- for(let i = 1; i <= ilosc; i++){
- x=prompt("Podaj liczbÄ " +i)
- document.write(parseInt(x))
- if(ilosc-i >= 1)
- document.write("+");
- suma += parseInt(x);
- }
- document.write("="+suma+"<br/>")
- }
- function srednia()
- {
- let x = prompt("Podaj iloĹÄ liczb");
- let ilosc = parseInt(x);
- let srednia = 0.0;
- for(let i = 1; i <= ilosc; i++){
- do
- {
- x=prompt("Podaj liczbÄ " +i)
- y = parseFloat(x);
- }while(x%2!=0)
- srednia += y;
- }
- srednia = srednia * 1.0 / ilosc;
- document.write(srednia);
- }
- function pitagorejskie(a, b ,c)
- {
- return (a*a+b*b==c*c);
- }
- function doPitagorejskich()
- {
- let x = prompt("Podaj liczbÄ a");
- let a = parseInt(x);
- x = prompt("Podaj liczbÄ b");
- let b = parseInt(x);
- x = prompt("Podaj liczbÄ c");
- let c = parseInt(x);
- document.write(a+"*"+a+"+")
- document.write(b+"*"+b+"=")
- document.write(c+"*"+c+" to wyraĹźenie jest ")
- return pitagorejskie(a,b,c);
- }
- function pierwsza(y, i = 2)
- {
- if(i < y)
- {
- if(y % i != 0)
- return(pierwsza(y, ++i));
- else
- return false;
- }
- return true;
- }
- function wybor()
- {
- let x = prompt("Podaj wybĂłr: ")
- x = parseInt(x);
- document.body.innerHTML = '';
- switch(x)
- {
- case 1:
- suma();
- przyciskMenu();
- break;
- case 2:
- srednia();
- przyciskMenu();
- break;
- case 3:
- document.write(doPitagorejskich());
- przyciskMenu();
- break;
- case 4:
- let x = prompt("Podaj liczbÄ: ");
- let y = parseInt(x);
- document.write("Czy "+y+ " jest liczbÄ pierwszÄ : "+pierwsza(y));
- przyciskMenu();
- break;
- default:
- menu();
- };
- }
- menu();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement