Im having an issue with displaying javascript output without any user action

后端 未结 2 1519
日久生厌
日久生厌 2021-01-26 12:23

this is the Question: An integer is said to be prime if it is greater than 1 and divisible only by 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not.

相关标签:
2条回答
  • 2021-01-26 12:54

    You're importing the script in the <head>, so that's where it's output will go. Try moving it to the <body>.

    That's possibly the slowest way to find primes.

    edit — another problem is this:

                for(int i=2;i<n;i++)
    

    There is no int keyword in JavaScript - it's var. That would cause a syntax error, which would show up in the error console. Neither is there a boolean keyword (declaration of "prime"). It's important to keep the error console open while doing any HTML/JavaScript development.

    0 讨论(0)
  • 2021-01-26 13:08

    This is because you are attempting to write the <textarea> to the <head> element. Try loading/executing your script within the <body>.

    0 讨论(0)
提交回复
热议问题