Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Post Timeline

added 127 characters in body
Source Link
Quentin
  • 948.9k
  • 137
  • 1.3k
  • 1.4k

Your problem is:

thirdnum==parseInt(number3); is a comparison, not an assignment, so thirdnum will always be 0.

Since you are multiplying by thirdnum, and anything ×ばつ 0 is 0, you will always get 0 as the output.

Change == to =.

This would have been picked up if you had QAed your code with JS Hint .


Your bad practises which you should fix are:

  1. num1.value assumes global JS variables will be created for every element with an id. Don't assume that, use document.getElementById
  2. parseInt(number1) doesn't have a radix. Always specify the number system you are using (normally base 10) so it isn't inferred from the data for unexpected results: parseInt(number1, 10);
  3. <form name="Example1">, the name attribute on forms is a legacy from before the id attribute had come around properly. Use id to identify elements for client side code.
  4. onclick attributes do a poor job of separating concerns. Use addEventListener (or a library such as YUI or jQuery if you need to support old versions of IE).

Your problem is:

thirdnum==parseInt(number3); is a comparison, not an assignment, so thirdnum will always be 0.


Your bad practises which you should fix are:

  1. num1.value assumes global JS variables will be created for every element with an id. Don't assume that, use document.getElementById
  2. parseInt(number1) doesn't have a radix. Always specify the number system you are using (normally base 10) so it isn't inferred from the data for unexpected results: parseInt(number1, 10);
  3. <form name="Example1">, the name attribute on forms is a legacy from before the id attribute had come around properly. Use id to identify elements for client side code.
  4. onclick attributes do a poor job of separating concerns. Use addEventListener (or a library such as YUI or jQuery if you need to support old versions of IE).

Your problem is:

thirdnum==parseInt(number3); is a comparison, not an assignment, so thirdnum will always be 0.

Since you are multiplying by thirdnum, and anything ×ばつ 0 is 0, you will always get 0 as the output.

Change == to =.

This would have been picked up if you had QAed your code with JS Hint .


Your bad practises which you should fix are:

  1. num1.value assumes global JS variables will be created for every element with an id. Don't assume that, use document.getElementById
  2. parseInt(number1) doesn't have a radix. Always specify the number system you are using (normally base 10) so it isn't inferred from the data for unexpected results: parseInt(number1, 10);
  3. <form name="Example1">, the name attribute on forms is a legacy from before the id attribute had come around properly. Use id to identify elements for client side code.
  4. onclick attributes do a poor job of separating concerns. Use addEventListener (or a library such as YUI or jQuery if you need to support old versions of IE).
Source Link
Quentin
  • 948.9k
  • 137
  • 1.3k
  • 1.4k

Your problem is:

thirdnum==parseInt(number3); is a comparison, not an assignment, so thirdnum will always be 0.


Your bad practises which you should fix are:

  1. num1.value assumes global JS variables will be created for every element with an id. Don't assume that, use document.getElementById
  2. parseInt(number1) doesn't have a radix. Always specify the number system you are using (normally base 10) so it isn't inferred from the data for unexpected results: parseInt(number1, 10);
  3. <form name="Example1">, the name attribute on forms is a legacy from before the id attribute had come around properly. Use id to identify elements for client side code.
  4. onclick attributes do a poor job of separating concerns. Use addEventListener (or a library such as YUI or jQuery if you need to support old versions of IE).
default

AltStyle によって変換されたページ (->オリジナル) /