5 Replies - 676 Views - Last Post: 14 September 2013 - 07:27 PM

#1 b_derick   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-September 13

Coding javascript help?

Posted 14 September 2013 - 10:17 AM

Coding javascript help?
Question: the folowing code answer is 82 but i don't know how to came the answer so please explain as // single line comment the step by step......

<script>
x=2;
for(i=1; i<10; i++)
{
if (i>5)
break;
j=i+1;
while(j<10)
{
x=x+i;
j+=1;
}
}
document.write(x)
</script>

This post has been edited by andrewsw: 14 September 2013 - 10:21 AM
Reason for edit:: Please use code tags

Is This A Good Question/Topic? 0
  • +

Replies To: Coding javascript help?

#2 andrewsw   User is offline

  • Bouncy!
  • member icon

Reputation: 6563
  • View blog
  • Posts: 26,615
  • Joined: 12-December 12

Re: Coding javascript help?

Posted 14 September 2013 - 10:22 AM

Please wrap your code in [ code ] tags, and use a sensible title for you question.

But you haven't asked a question: we are not a free coding, or commenting service.
So what is your specific question? (I might edit your title for you once you've asked a question.)

BTW Is it your assignment to comment this code?

This post has been edited by andrewsw: 14 September 2013 - 10:29 AM

Was This Post Helpful? 0
  • +
  • -

#3 laytonsdad   User is offline

  • Let it rip!
  • member icon

Reputation: 466
  • View blog
  • Posts: 1,992
  • Joined: 30-April 10

Re: Coding javascript help?

Posted 14 September 2013 - 01:23 PM

Please give a specific question for us to be able to help you.
Was This Post Helpful? 0
  • +
  • -

#4 JMRKER   User is offline

  • D.I.C Addict
  • member icon

Reputation: 134
  • View blog
  • Posts: 868
  • Joined: 25-October 08

Re: Coding javascript help?

Posted 14 September 2013 - 05:26 PM

Answer the question yourself by placing several "alert('Values of: i, j, x:'+i+', '+j+', '+x);"
at different places within your script. You can then figure out what is happening.
Was This Post Helpful? 1
  • +
  • -

#5 snoj   User is offline

  • Married Life
  • member icon

Reputation: 93
  • View blog
  • Posts: 3,583
  • Joined: 31-March 03

Re: Coding javascript help?

Posted 14 September 2013 - 05:52 PM

Alert() can be annoying. Maybe use console.log , warn, or error instead.
Was This Post Helpful? 0
  • +
  • -

#6 JMRKER   User is offline

  • D.I.C Addict
  • member icon

Reputation: 134
  • View blog
  • Posts: 868
  • Joined: 25-October 08

Re: Coding javascript help?

Posted 14 September 2013 - 07:27 PM

View Postsnoj, on 14 September 2013 - 06:52 PM, said:

Alert() can be annoying. Maybe use console.log , warn, or error instead.


True, but as the OP looks like a beginner trying to use document.write,
I would think for this level, the alert would be appropriate.
It would allow him/her to solve the question posed by themselves.

Plus, if OP is using MSIE, those other options may not be available.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1