Could somehelp me with this javascript question

+1 stefan morrissey · November 9, 2015
1.     (a) Print out every integer between 0 and 77 (inclusive).
(b) Print out every even integer between 0 and 77 (inclusive).


<script>

for (var i = i ; i > 78; i = i + 1)
{
document.write(I)
}
</script>

Post a Reply

Replies

Oldest  Newest  Rating
0 stefan morrissey · November 18, 2015
thanks for the help mate i appreciated it
0 Scott Walker · November 18, 2015


function getNumbers(){ 
for (var i=0; i<=77;i++){
document.write(i);
}
for (var i=0;i<=77;i++){
if (i %2 ==1){
document.write(i);
}



That's not quite right.


for even numbers it would be:


for (var i=0;i<=77;i++){
if (i % 2 == 0){
document.write(i);
}
}


0 Ivan Kušaković · November 9, 2015
This is correct code: 


      
function getNumbers(){                 
for (var i=0; i<=77;i++){
document.write(i);
}
for (var i=0;i<=77;i++){
if (i %2 ==1){
document.write(i);
}


             
  • 1

Javascript

107,032 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators