Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

JavaScript- How to check if a number divides in another number without a quotient?

javascript

Best Answer WingedPanther73, 13 February 2015 - 10:02 AM

Use the modulus operator (%), which gives the remainder. For example, 20%5 == 0, because 20/5 is 4 remainder 0, but 18%5 == 3 because 18/5 is 3 remainder 3.

Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1 IceCream

IceCream

    CC Newcomer

  • Member
  • PipPip
  • 11 posts

Posted 13 February 2015 - 09:50 AM

Hello fellows,

I recently started learning JavaScript, after understanding HTML and CSS.

I am trying to code a program (with JS) that will calculate the sum of all numbers between 1-100 that divide in 5 or 7 without a reminder, using variables and for loop.

I think I can figure out how to code everything except one thing- how to check if a number divides in another number without a reminder?

I hope I explained myself well.

Thank you! :)

*I got confused in the headline, I meant "reminder" instead of "quotient". My intention is how to check if a number divides in another number and the result is an integer.


Edited by IceCream, 13 February 2015 - 10:04 AM.


#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 13 February 2015 - 10:02 AM   Best Answer

Use the modulus operator (%), which gives the remainder. For example, 20%5 == 0, because 20/5 is 4 remainder 0, but 18%5 == 3 because 18/5 is 3 remainder 3.


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 IceCream

IceCream

    CC Newcomer

  • Member
  • PipPip
  • 11 posts

Posted 13 February 2015 - 10:25 AM

Use the modulus operator (%), which gives the remainder. For example, 20%5 == 0, because 20/5 is 4 remainder 0, but 18%5 == 3 because 18/5 is 3 remainder 3.

Thank you very much for the quick respondence! You helped a lot and I managed to code the program I wanted. :)






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download