I was doing my WEB programming assignment for classes today. To make it simple I keep every exercise in same HTML file. While writing my last exercise , i couldn't call the new function. I tried few test functions but nothing worked. Although when I put the script in external file , it started to work.
The way I handle forms and etc. is on purpose - it's how my teacher wants it.
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
button
{
height: 50px;
width: 200px;
background-color: rgb(20 , 255 , 150);
color: white;
}
#lista5 button
{
background-color: rgb(20 , 150 , 255);
}
#lista4
{
float: left;
width: 200px;
background-color: grey;
}
#lista5
{
float: left;
width: 200px;
}
#lista6
{
color: white;
clear: both;
background-color: grey;
width: 800px;
min-height: 500px;
padding: 10px;
}
#zad12
{
margin-left: 300px;
}
.form
{
background-color: lightgray;
color: black;
margin: 25px;
padding: 20px;
}
.form button
{
height: 25px;
width: 100px;
color: black;
}
</style>
<script src="9.js"></script>
<script>
function zad1 ()
{
var wydzial = prompt("podaj swój wydział");
alert(" Politechnika Wrocławska , wydział : " + wydzial);
document.write("politechnika Wrocławska <br>" , wydzial);
}
function zad2 ()
{
var liczba = prompt("podaj liczbe");
if (liczba > 0)
{
document.write("<font color=green>" + liczba + "</style>");
}
else if (liczba == 0)
{
document.write(liczba);
}
else
{
document.write("<font color=red>" + liczba + "</style>");
}
}
function zad3()
{
var a = prompt("podaj liczbe"); parseFloat(a);
var b = prompt("podaj liczbe"); parseFloat(b);
if (a > b)
{
document.write("<h3>" + a + "</h3>");
}
else if (a < b)
{
document.write("<h3>" + b + "</h3>");
}
else
{
document.write("liczby są równe , liczba : " + "<h3>" + a + "</h3>");
}
}
function zad4 ()
{
var a = prompt("podja liczbe a");
a = parseFloat(a);
var b = prompt("podaj liczbe b");
b = parseFloat(b);
var suma = suma = a + b;
document.write(suma);
alert(suma);
}
function zad5()
{
var a = prompt("podja liczbe a");
a = parseInt(a);
var b = prompt("podaj liczbe b");
b = parseInt(b);
var d = a / b; // dzielna
if (a%b == 0)
{
document.write(d);
}
else
{
document.write("<h1><font color=red>\n\
liczba nie może zostać podzielona debilu -,- </font></h1>");
}
}
function zad6()
{
var a = 1; var b = 7;
while (a<=7 || b>0)
{
if (a<8)
{
document.write("<h" + a + "> wydział informatyki i zarządzania</h" + a + ">");
document.write("<br>");
a++;
}
else
{
document.write("<h" + b + "> wydział informatyki i zarządzania</h" + b + ">");
document.write("<br>" + b);
b--;
}
}
}
function zad7() // 5,2
{
var lp = prompt("oznacz początek przedziału");
var lk = prompt("oznacz koniec przedziału");
var i = lp; // iterator
if (lk < lp)
{
alert("błąd")
}
while (i<=lk)
{
document.write(i + " ,");
i++;
}
}
function zad8()
{
var lp = prompt("oznacz początek przedziału"); lp = parseInt(lp);
var lk = prompt("oznacz koniec przedziału"); lk = parseInt(lk);
var i = lp; // iterator
var suma = i;
while (i<=lk)
{
document.write("suma = " + suma + "<br>");
i++;
suma = suma + i;
}
}
//zadanie 9 w pliku 9.js
//zad 10 tak smao
function zad11()
{
var n = prompt("podaj ilość liczb");
n = parseInt(n);
var i = 0; //iterator
var v = 0; //wartość - value
var suma = 0;
while (i != n)
{
v = prompt("podaj wartość");
v = parseInt(v);
suma = suma + v;
i++;
v=0;
}
document.write(suma);
}
function zad12 ()
{
var i = 0;
var j = 0;
var x = [];
var z = 0; //zera
var suma = 0; suma = parseInt(suma);
var mi = 0;
while (i < 15)
{
x[i] = prompt("podaj liczbe");
x[i] = parseInt(x[i]);
document.write(x[i] + "<br>");
if (x[i] > 0)
{
suma = suma + x[i];
j++;
}
if (x[i] == 0)
{
z++;
}
i++;
}
mi = suma / j;
document.write("suma = " + suma + "<br>" +
"średnia = " + mi + "<br>" +
"zera = " + z + "<br>");
}
function zad13()
{
var a;
var b;
a = document.getElementById('l1').value; a = parseInt(a);
b = document.getElementById('l2').value; b = parseInt(b);
document.getElementById('sum').value = a + b;
return false;
}
function zad14()
{
var a; var b; var c;
function top (a , b ,c)
{
var a; var b; var c;
alert ( a + b + c );
if (a > b && a > c)
return a;
else if (b > a && b > c)
return b;
else if (c > a && c > b)
return c;
}
a = document.getElementById('l3').value; a = parseInt(a);
b = document.getElementById('l4').value; b = parseInt(b);
c = document.getElementById('l5').value; c = parseInt(c);
document.getElementById('top').value = top(a , b , c);
return false;
}
function zad15()
{
var a; var b;
a = document.getElementById('l6').value; a = parseInt(a);
b = document.getElementById('l7').value; b = parseInt(b);
document.getElementById('sum2').value = a + b;
document.getElementById('subt').value = a - b;
document.getElementById('multi').value = a * b;
document.getElementById('div').value = a / b;
return false;
}
function zad16(t)
{
var t;
var a = document.getElementById('l8').value; a = parseFloat(a);
var b = document.getElementById('l9').value; b = parseFloat(b);
switch (t)
{
case 1 :
{
document.getElementById('wyn').value = a + b;
return false;
}
case 2 :
{
document.getElementById('wyn').value = a - b;
return false;
}
case 3 :
{
document.getElementById('wyn').value = a * b;
return false;
}
case 4 :
{
document.getElementById('wyn').value = a / b;
return false;
}
}
//nastepne zadanie jest w dołączonym pliku , jakiś dziwny
//błąd ograniczający długość kodu...
//THIS WON'T WORK HERE
/* function zad17(t)
{
var t;
var PLN = document.getElementById('PLN').value;
PLN = parseFloat(PLN);
var USD = PLN / 3.10;
var EUR = PLN / 4.19;
var CHR = PLN / 3.41;
if (t === 2)
{
document.getElementById('USD').value = USD;
document.getElementById('EUR').value = EUR;
document.getElementById('CHR').value = CHR;
return false;
}
else
{
document.getElementById('USD').value = null;
document.getElementById('EUR').value = null;
document.getElementById('CHR').value = null;
document.getElementById('PLN').value = null;
return false;
}
}
*/
</script>
</head>
<body>
<div>
<div id="lista4">
<button onclick="zad1()"> zadanie 1 </button>
<br>
<button onclick="zad2()"> zadanie 2 </button>
<br>
<button onclick="zad3()"> zadanie 3 </button>
<br>
<button onclick="zad4()"> zadanie 4 </button>
<br>
<button onclick="zad5()"> zadanie 5 </button>
</div>
<div id="lista5">
<button onclick="zad6()"> zadanie 1 </button>
<br>
<button onclick="zad7()"> zadanie 2 </button>
<br>
<button onclick="zad8()"> zadanie 3 </button>
<br>
<button onclick="max(0)"> zadanie 4 </button>
<br>
<button onclick="zad10()"> zadanie 5 </button>
<br>
<button onclick="zad11()"> zadanie 6 </button>
<br>
</div>
</div>
<div id="lista6">
<button id="zad12" onclick="zad12()"> zadanie </button>
<div class="form">
<form id="zad13">
Sumowanie <br>
Podaj Liczbe 1 : <input type="text" value="0" id="l1"><br>
Podaj Liczbe 2 : <input type="text" value="0" id="l2"><br><br>
<button onclick="return zad13()"> oblicz </button>
Wynik = <input type="text" value="0" id="sum" disabled>
</form>
</div>
<div class="form">
<form id="zad14">
Największa <br>
Podaj Liczbe 1 : <input type="text" value="0" id="l3"><br>
Podaj Liczbe 2 : <input type="text" value="0" id="l4"><br>
Podaj Liczbe 3 : <input type="text" value="0" id="l5"><br><br>
<button onclick="return zad14()"> oblicz </button>
Wynik = <input type="text" value="0" id="top" disabled>
</form>
</div>
<div class="form">
<form id="zad15">
<div style="float: left; width: 50%">
Podaj Liczbe 1 : <input type="text" value="0" id="l6"><br>
Podaj Liczbe 2 : <input type="text" value="0" id="l7"><br><br><br>
<button onclick="return zad15()"> oblicz </button>
</div>
<div>
<div style="float: left; line-height: 130%;">
suma <br>
różnica <br>
iloczyn <br>
iloraz <br>
</div>
<div>
=<input type="text" value="0" id="sum2" disabled> <br>
=<input type="text" value="0" id="subt" disabled> <br>
=<input type="text" value="0" id="multi" disabled> <br>
=<input type="text" value="0" id="div" disabled> <br>
<br>
</div>
</div>
</form>
</div>
<div class="form">
<form id="zad16">
<div style="float: left; width: 50%">
Podaj Liczbe 1 : <input type="text" value="0" id="l8"><br>
Podaj Liczbe 2 : <input type="text" value="0" id="l9"><br><br>
wynik : <input type="text" value="0" id="wyn" disabled >
</div>
<div>
<button onclick="return zad16(1)"> sumuj </button> <br>
<button onclick="return zad16(2)"> odejmuj </button><br>
<button onclick="return zad16(3)"> Mnóż </button><br>
<button onclick="return zad16(4)"> dziel </button><br>
<br>
</div>
</form>
</div>
<div class="form">
<form id="zad17">
<div style="float: left; width: 50%; text-align: center;">
<b>kwota PLN</b> <br>
<input type="text" id="PLN">
<br> <br> <br>
</div>
<div>
<input type="text" id="EUR" disabled> EUR
<input type="text" id="USD" disabled> USD
<input type="text" id="CHR" disabled> CHR
<br>
</div>
<div style="clear: both; text-align: center; ">
<button onclick="return zad17(1)"> nowa kwota </button>
<button onclick="return zad17(2)"> przelicz </button>
</div>
</form>
</div>
</div>
</body>
the external 9.js file :
function max (max) //zad 9
{
var p1 = prompt("podaj liczbe 1");
var p2 = prompt("podaj liczbe 2");
var max;
if (p1 > p2)
{
max = p1;
}
else
{
max = p2;
}
alert(max);
}
function zad10()
{
var lp = prompt("oznacz początek przedziału"); lp = parseInt(lp);
var lk = prompt("oznacz koniec przedziału"); lk = parseInt(lk);
var i = lp; // iterator
var suma = i;
while (i<=lk)
{
document.write("suma = " + suma + "<br>");
i++;
suma = suma + i;
}
}
function zad17(t) / this will work
{
var t;
var PLN = document.getElementById('PLN').value;
PLN = parseFloat(PLN);
var USD = PLN / 3.10;
var EUR = PLN / 4.19;
var CHR = PLN / 3.41;
if (t === 2)
{
document.getElementById('USD').value = USD;
document.getElementById('EUR').value = EUR;
document.getElementById('CHR').value = CHR;
return false;
}
else
{
document.getElementById('USD').value = null;
document.getElementById('EUR').value = null;
document.getElementById('CHR').value = null;
document.getElementById('PLN').value = null;
return false;
}
}