Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="pl">
- <head>
- <meta charset="utf-8">
- <title>Kalkulator</title>
- <style>
- body{
- font-family: Comic Sans MS;
- }
- #kalkulator{
- height:460px;
- width:450px;
- background-color:LightGray;
- border:3px solid black;
- }
- #lcd{
- margin:25px;;
- height:70px;
- width:400px;
- background-color:Gray;
- border: 3px solid black;
- text-align:right;
- font-size:50px;
- }
- .radius{
- border-top-right-radius: 10px;
- border-top-left-radius: 10px;
- border-bottom-right-radius: 10px;
- border-bottom-left-radius: 10px;
- }
- .przycisk{
- text-align:center;
- padding:10px;
- font-size:30px;
- background-color:gray;
- height:76px;
- width:76px;
- border:3px solid black;
- }
- </style>
- <script type="text/javascript">
- //zmienne globalne--------------------------------------------------------------
- var x="";
- var y="";
- var z=0;
- var op;
- //funkcje liczb i wyswietlania--------------------------------------------------
- function zmiana() {
- if(z==1){
- z=0;
- } else if(z==0){
- z=1;
- }
- }
- function cyfra(n)
- {
- if (z==0){
- x+=n;
- document.getElementById("lcd").value=x;
- }
- else if (z==1)
- {
- y+=n;
- document.getElementById("lcd").value=y;
- }
- }
- function ostatnia()
- {
- if (z==0){
- x=x.substring(0,x.length-1);
- document.getElementById("lcd").value=x;
- }
- else if (z==1)
- {
- y=y.substring(0,y.length-1);
- document.getElementById("lcd").value=y;
- }
- }
- //operatory------------------------------------------------------------------------
- function operator(o)
- {
- op=o;
- if (op=='pierwiastek'){
- x = Math.sqrt(x);
- document.getElementById("lcd").value= x;
- }else if (op=='potega'){
- x = x*x;
- document.getElementById("lcd").value=x;
- }else if (op=='1/x'){
- x = 1/x;
- document.getElementById("lcd").value=x;
- }else{
- z++;
- document.getElementById("lcd").value=y;
- }
- }
- //funkcja obliczająca--------------------------------------------------------------
- function rownasie()
- {
- if (op=='+'){
- x=x-(-y);
- }else if (op=='-'){
- x=x-y;
- }else if (op=='*'){
- x=x*y;
- }else if (op=='/'){
- if((!isNaN(x))&&(!isNaN(y))&&(y!=0)){
- x = x/y;
- }else{
- alert("nie dziel zjebie przez 0");
- }
- }
- document.getElementById("lcd").value= x;
- z=0;
- y=0;
- }
- </script>
- </head>
- <body>
- <center>
- <div id="kalkulator" class="radius">
- <input type="text" id="lcd">
- <table>
- <tr>
- <td>
- <input class="radius przycisk" type="button" value="+" onclick="operator('+')" />
- <input class="radius przycisk" type="button" value="-" onclick="operator('-')" />
- <input class="radius przycisk" type="button" value="*" onclick="operator('*')" />
- <input class="radius przycisk" type="button" value="/" onclick="operator('/')" />
- <input class="radius przycisk" type="button" value="C" onclick="location.reload()" />
- </td>
- </tr>
- <tr>
- <td>
- <input class="radius przycisk" type="button" value=7 onclick="cyfra(7)" />
- <input class="radius przycisk" type="button" value=8 onclick="cyfra(8)" />
- <input class="radius przycisk" type="button" value=9 onclick="cyfra(9)" />
- <input class="radius przycisk" type="button" value="√x" onclick="operator('pierwiastek')" />
- <input class="radius przycisk" type="button" value="CE" onclick="ostatnia()" />
- </td>
- </tr>
- <tr>
- <td>
- <input class="radius przycisk" type="button" value=4 onclick="cyfra(4)" />
- <input class="radius przycisk" type="button" value=5 onclick="cyfra(5)" />
- <input class="radius przycisk" type="button" value=6 onclick="cyfra(6)" />
- <input class="radius przycisk" type="button" value=0 onclick="cyfra(0)" />
- <input class="radius przycisk" type="button" value='x^2' onclick="operator('potega')" />
- </td>
- </tr>
- <tr>
- <td>
- <input class="radius przycisk" type="button" value=1 onclick="cyfra(1)" />
- <input class="radius przycisk" type="button" value=2 onclick="cyfra(2)" />
- <input class="radius przycisk" type="button" value=3 onclick="cyfra(3)" />
- <input class="radius przycisk" type="button" value="=" onclick="rownasie()" />
- <input class="radius przycisk" type="button" value="1/x" onclick="operator('1/x')" />
- </td>
- </tr>
- </table>
- </div>
- </center>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment