Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a litle bit of an idea here, but I\'m having a problem with this one. I\'

ID: 3545939 • Letter: I

Question

I have a litle bit of an idea here, but I'm having a problem with this one.  I'm to write an HTML/Javascript where

:

Allow the user to click on one of four buttons (in Javascript) that appear on the page. These buttons will affect the displayed number as follows:


The first button - Use a "FOR loop" to count down by 1

The second button - Use a "WHILE loop" to count down by 2

The third button -  Use a "FOR loop" to count up by 1

The fourth button - Use a "WHILE" loop to count up by 2


We'll assume that the count starts at ZERO, of course.  


This should be written in Javascript, of course.  Thank you for your help!

Explanation / Answer

Hi ... well i strictly not fallowed ur requiremnr becoz i felt loops were no use + extra burden here


Simple way is (MY WAY)


<html>

<head>

<script type="text/javascript">


var count = 0;

function countClicks1()

{

count = count - 1;

document.getElementById("demo").innerHTML = count;

}

function countClicks2()

{

count = count - 2;

document.getElementById("demo").innerHTML = count;

}

function countClicks3()

{

count = count + 1;

document.getElementById("demo").innerHTML = count;

}

function countClicks4()

{

count = count + 2;

document.getElementById("demo").innerHTML = count;

}


</script>

</head>

<body>

<p id="demo">NUMBER</p>

<button type="button1">count down by 1 </button>

<button type="button2">count down by 2 </button>

<button type="button3">count up by 1 </button>

<button type="button4">count up by 2 </button>


</body>

</html>


WAY 2 (YOUR REQUIREMMENT )


<html>

<head>

<script type="text/javascript">


var count = 0;

function countClicks1()

{

for(var x = count ; x >= count ;x -=2)

{

count = count - 1 ;

document.getElementById("demo").innerHTML = count;

}

}


function countClicks2()

{

var x= count ;

while(x <= count)

{

count = count - 2 ;

document.getElementById("demo").innerHTML = count;

}

}



function countClicks3()

{

for(var x = count ; x >= count ;x -=1)

{

count = count + 1 ;

document.getElementById("demo").innerHTML = count;

}

}



function countClicks4()

{

var x = count ;

while(x >= count)

{

count = count + 2 ;

document.getElementById("demo").innerHTML = count;

}

}


</script>

</head>

<body>

<p id="demo" align="center">NUMBER</p>

<button type="button1" >count down by 1 </button>

<button type="button2" >count down by 2 </button>

<button type="button3" >count up by 1 </button>

<button type="button4" >count up by 2 </button>


</body>

</html>


## Trick here is simple in for loop we want just one sucessful intertation later we will forcefully make the condition false lol