Jump to content

JS help


TheFiresInTheSky

Recommended Posts

im trying to make something that would randomely select a number. id like to be able to have a pop-up where you could enter 2 numbers and have it select a random number including those numbers. ive checked websites and asked around but no one knew how to(using JS of course).

Link to comment
Share on other sites

FROM: lokoike

I found this page:

http://www.w3schools.com/js/js_obj_math.asp

 

It has a bunch of math operators, and it even lets you make and test a page using them.

 

I was thinking if you wanted to make it choose a number between 0-10, you could use the random function, then multiply your random number by 10, and then round it to a whole number.

 

For example, random generates: 0.6782433.

 

Take that x10 and you get 6.782433. Then round it to a whole number and you get 7.

 

 

 

problem: i need all variations of numbers

Link to comment
Share on other sites

 

problem: i need all variations of numbers

Hmm... I wish I knew how to code in JS, all I've ever really done is BASIC. I have a suggestion, but I don't know if JS offers the capabilities to do it. Say you want a 4-digit whole number (anywhere from 0-9999):

 

Use the random function to create a random number, and then multiply it by 10. Then truncate it (as opposed to rounding it) so that the remainder is dropped and you are left with a whole number between 0-9. The reason you truncate instead of round is so that you don't accidently end up with 10 as your number. Hopefully JS has a truncate feature...

 

Then take that number and save it as a string. Hopefully JS can save numbers as strings...

 

Then, do the same process three more times, saving each of the numbers as strings, so that JS treats them like text instead of like numbers.

 

Once you have four 1-digit numbers saved as strings, add all of the strings together to make it one 4 character string. Perhaps you ended up with the numbers 0, 3, 4, and 1. Turn them into strings ("0","3","4", and "1") and add them together ("0341"). Hopefully JS can add the strings that you were hopefully able to make in the first place...

 

And finally, convert your 4-character string back into a number, in this case 341. Hopefully JS can do that too...

 

So, needless to say, this suggestion is based totally on the premise that JS contains basic string functions. If it does, that should solve your problem.

Save a tree, eat a beaver.

Save a tree, wipe with an owl.

 

Every time a bell rings, a thread gets hijacked!

ding, ding!

 

Give Andavari lots of money and maybe even consider getting K a DVD-RW drive.

 

If it's not Scottish, IT'S CRAP!!!

Link to comment
Share on other sites

  • Moderators

There's some sites that offer free scripts, albeit I don't know if they have your specific request. Google 'em to see if they help, you might even find a forum which you could join where people could help you step by step, or at the least give you direction.

Link to comment
Share on other sites

how would i select "random number between 1 and 25? what if i just said like random like links and such advertisements and run it off the internet?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.