whats the output for this???

var a;
var b;

for(a=1;a<=4;a++)
{
document.write(a +"<br>")
for{b=3;b<=5;b++)
{
document.write(b +"<br>")

}
}

Dani AI

Generated

A short diagnosis and a safe fix.

— the snippet is JavaScript (as others asked). The most likely cause of "no output" is a syntax error in the inner for statement; a syntax error prevents the browser from executing the script at all. Check the developer console (F12) for an error like "SyntaxError" and the line number.

A corrected, more robust approach (use block-scoped variables and avoid document.write once the page is loaded):

// put this in a script tag (or use defer) and ensure an element with id="out" exists
let html = '';
for (let i = 1; i <= 4; i++) {
  html += i + '<br>';
  for (let j = 3; j <= 5; j++) {
    html += j + '<br>';
  }
}
document.getElementById('out').innerHTML = html;

This prints the outer index, then the inner sequence on separate lines for each outer-loop iteration. Troubleshooting tips: open the console to see exact errors, ensure the <script> runs after the target element (or use defer), prefer console.log or DOM insertion over document.write, and declare loop counters with let so each loop iteration behaves predictably. See MDN on the for statement and document.write for reference: for statement and Document.write.

Recommended Answers

All 3 Replies

What Language is that?

looks like it might be html, but not certain

I think it's java script? Outputting numbers and HTML markup
And the output is something like this
1<br>3<br>2<br>4<br>3<br>5<br>
Or something similar.....
What is the program supposed to do?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.