Random numbers

+1 william appiah-dankwah · February 25, 2015

function Car(){
var Blank = 10;
var Car = 9;
var Bank = 3;
var Base = 5;


document.write(Math.random() * Blank +"," + Car +"," + Bank +"," + Base);

}



just wrote this code why isn't Math.random() making all the variable numbers random is there a better way of laying this out?

Post a Reply

Replies

Oldest  Newest  Rating
+1 Robert Herges · February 26, 2015
Is this what you were looking for?

function Car() {
var Blank = 10;
var Car = 9;
var Bank = 3;
var Base = 5;

document.write(randomize(Blank) + ", " + randomize(Car) + ", " + randomize(Bank) + ", " + randomize(Base));
}

function randomize(value) {
return Math.random() * value;
}

Car();
0 william appiah-dankwah · February 26, 2015
whats randomise why (Base) and (value ) why does the code work like that? yeah this is what i am trying to put together put Math.floor in to round the numbers
0 Robert Herges · February 26, 2015
You should watch this JavaScript tutorial: https://www.thenewboston.com/videos.php?cat=10&video=16955

It goes over functions and the return statement. You can reply on this thread again if you have any more questions after watching the video :P
0 william appiah-dankwah · February 27, 2015
So what's value?
  • 1

Javascript

107,093 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators