Jump to content

urgent help alert even and odd numbers with for loop please


Recommended Posts

help again internal javascript not displaying what wrong am i doing?

 

<html>

<head>

<title>ODD/EVEN/AVEREGE</title>

<script type="text/javascript">

 

 

function even()

{

 

var even

even = document.results.even.value;

var even=0;

for (even=1;even < 50;even++)

{

alert(even);

 

}

 

function odd()

{

var odd

odd = document.results.odd.value;

var odd=0;

for (odd=1;odd < 20;odd++)

{

alert(odd++);

 

}

</script>

 

</head>

 

<body>

 

<form action="#" name="results" method="post">

<input type="button" name="even" value="Even numbers 1-50" onClick="even();"/>

<input type="button" name="odd" value="Odd numbers 1-20" onClick="odd();"/>

<input type="reset" value="reset"/>

</form>

       

</body>

</html>

You probably would have seen some trouble by just indenting your code. :code_php_tags:

function even()
{

    var even
    even = document.results.even.value;
    var even=0;
    for (even=1;even < 50;even++)
    {
        alert(even);

    }
// see something missing here?

function odd()
{
    var odd
    odd = document.results.odd.value;
    var odd=0;
    for (odd=1;odd < 20;odd++)
    {
        alert(odd++);

    }

// see something missing here?

something like this should work

 

<html>
<head>
<title>ODD/EVEN/AVEREGE</title>
<script type="text/javascript">


function even()
{
    for (even=2;even <= 50;even=even+2)
    {
        alert(even);
    }
}

function odd()
{
    for (odd=1;odd < 20;odd=odd+2)
    {
        alert(odd);

    }
}
</script>

</head>

<body>

<form action="#" name="results" method="post">
<input type="button" name="evenbutton" value="Even numbers 1-50" onClick="even();"/>
<input type="button" name="oddbutton" value="Odd numbers 1-20" onClick="odd();"/>
<input type="reset" value="reset"/>
</form>
       
</body>
</html>

please help me when i click button nothing is displaying :confused:

 

<html>
<head>
<title>ODD/EVEN/AVEREGE</title>
<script type="text/javascript">

function even()
{

    var even
    even = document.results.even.value;
    var even=0;
    for (even=1;even < 50;even++)
    {
        alert(even);

    }


function odd()
{
    var odd
    odd = document.results.odd.value;
    var odd=0;
    for (odd=1;odd < 20;odd++)
    {
        alert(odd++);

    }





</script>

</head>

<body>
<input type="button" name="odd" value="Even numbers 1-50" onclick="eve();"/>
<input type="button" name="odd" value="Odd numbers 1-20" onclick="odd();"/>
<input type="reset" value="reset"/>
</form>
        
</body>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.