Zaloguj | Zarejestruj | FAQ
Anonymous

Success! cool code that works (please read)

+ Odpowiedz

Posty: 3 Strona 1 z 1


Success! cool code that works (please read)

przez soccerwebsitemaker » N sty 29, 2012 8:15 pm

Hi everyone. I finally figured out all the problems in my code and made one good one. please copy and paste the html and js documents and save them right. then open the file and you will have a fun page. thanks for reading.

HTML code (.html or .htm):

<html>

<head>

<script type="text/javascript" src="thefunjavascript.js"></script>

</head>

<body>

<p>Write a number in the box. Modify it in three different ways.<input type="text" id="squaretext" /></p>

<input type="button" value="Double it" id="doublebutton" />

<input type="button" value="Triple it" id="triplebutton" />

<input type="button" value="Square it" id="squarebutton" />

<script type="text/javascript">

</script>

</body>

</html>




JavaScript code: (.js)

function init()

{

var mySquareButton = document.getElementById("squarebutton");

mySquareButton.onclick = square;

var MyDoubleButton = document.getElementById("doublebutton");

MyDoubleButton.onclick = double;

var MyTripleButton = document.getElementById("triplebutton");

MyTripleButton.onclick = triple;

}

onload = init;

function square()

{

var num = parseInt(document.getElementById('squaretext').value);

if (isNaN(num))

{

alert("Enter a number");

}

else

{

var answer = Math.sqrt(num);

alert(answer);

}

}

function double()

{

var num = parseInt(document.getElementById('squaretext').value);


if (isNaN(num))

{

alert("Enter a number");

}

else

{

doubleanswer = num * 2;

alert(doubleanswer);

}

}

function triple()

{

var num = parseInt(document.getElementById('squaretext').value);


if (isNaN(num))

{

alert("Enter a number");

}

else

{

tripleanswer = num * 3;

alert(tripleanswer);

}

}







Thanks for reading!
Avatar użytkownika

soccerwebsitemaker

  • Posty: 138
  • Dołączył(a): So gru 31, 2011 6:25 pm
--
Coins. Profile. Games. Chat. Fun.

CoinAwards.

Check it out at http://www.coinawards.net63.net/

Re: Success! cool code that works (please read)

przez mariaantonietta » Pn sty 30, 2012 11:40 am

Hi soccerwebsitemaker,

Great demo!

soccerwebsitemaker napisał(a):Hi everyone. I finally figured out all the problems in my code and made one good one. please copy and paste the html and js documents and save them right. then open the file and you will have a fun page. thanks for reading.

HTML code (.html or .htm):

<html>

<head>

<script type="text/javascript" src="thefunjavascript.js"></script>

</head>

<body>

<p>Write a number in the box. Modify it in three different ways.<input type="text" id="squaretext" /></p>

<input type="button" value="Double it" id="doublebutton" />

<input type="button" value="Triple it" id="triplebutton" />

<input type="button" value="Square it" id="squarebutton" />

<script type="text/javascript">

</script>

</body>

</html>




JavaScript code: (.js)

function init()

{

var mySquareButton = document.getElementById("squarebutton");

mySquareButton.onclick = square;

var MyDoubleButton = document.getElementById("doublebutton");

MyDoubleButton.onclick = double;

var MyTripleButton = document.getElementById("triplebutton");

MyTripleButton.onclick = triple;

}

onload = init;

function square()

{

var num = parseInt(document.getElementById('squaretext').value);

if (isNaN(num))

{

alert("Enter a number");

}

else

{

var answer = Math.sqrt(num);

alert(answer);

}

}

function double()

{

var num = parseInt(document.getElementById('squaretext').value);


if (isNaN(num))

{

alert("Enter a number");

}

else

{

doubleanswer = num * 2;

alert(doubleanswer);

}

}

function triple()

{

var num = parseInt(document.getElementById('squaretext').value);


if (isNaN(num))

{

alert("Enter a number");

}

else

{

tripleanswer = num * 3;

alert(tripleanswer);

}

}







Thanks for reading!
Avatar użytkownika

mariaantonietta

  • Posty: 64
  • Dołączył(a): Pn paź 31, 2011 7:23 pm

Re: Success! cool code that works (please read)

przez soccerwebsitemaker » Pt kwi 27, 2012 11:04 am

Did you save it correctly, in the same file, and with a link to javascript on the head section (maybe i forgot to include it...)

HTML saves as .html or .htm

JS saves as .js


Wait, i know why. It's because maybe you didn't call your javascript "thefunjavascript.js"

that should be the problem...
Avatar użytkownika

soccerwebsitemaker

  • Posty: 138
  • Dołączył(a): So gru 31, 2011 6:25 pm
--
Coins. Profile. Games. Chat. Fun.

CoinAwards.

Check it out at http://www.coinawards.net63.net/


+ Odpowiedz

Strona 1 z 1

cron