This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-03-04 16:05:31

poemon1
Scratcher
Registered: 2011-01-12
Posts: 500+

Javascript html compatibility

Hello, scratchers. I'm learning HTML, and I need help. How do you create a random number with a text after it? i tried this:

Code:

<script type="text/javascript">
var x=Math.floor((math.random()*11011) & "People online")
document.write(x)

I searched EVERYWHERE ON THE INTERNET! Please help me.


http://i47.tinypic.com/rrqe13.gif

Offline

 

#2 2012-03-04 16:18:35

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: Javascript html compatibility

I'm not an expert on JS, so sorry if I'm wrong, but I think you are missing a ")." Also, maybe there's another way to do it, but I use a "+" instead of a "&" for concatenation.  So...

Code:

<script type="text/javascript">
var x=Math.floor((math.random()*11011)) + "People online")
document.write(x)

Last edited by scmb1 (2012-03-04 16:20:24)


http://i48.tinypic.com/2z5pqad.png

Offline

 

#3 2012-03-04 16:19:24

poemon1
Scratcher
Registered: 2011-01-12
Posts: 500+

Re: Javascript html compatibility

scmb1 wrote:

I'm not an expert on JS, so sorry if I'm wrong, but I think you are missing a ")." Also, maybe there's another way to do it, but I use a "+" instead of a "&" for concatenation.  So...

Code:

<script type="text/javascript">
var x=Math.floor((math.random()*11011)) + "People online")
document.write(x)

Thanks. I'll try it  smile


http://i47.tinypic.com/rrqe13.gif

Offline

 

#4 2012-03-04 16:21:41

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: Javascript html compatibility

poemon1 wrote:

scmb1 wrote:

I'm not an expert on JS, so sorry if I'm wrong, but I think you are missing a ")." Also, maybe there's another way to do it, but I use a "+" instead of a "&" for concatenation.  So...

Code:

<script type="text/javascript">
var x=Math.floor((math.random()*11011)) + "People online")
document.write(x)

Thanks. I'll try it  smile

And you left off the semi-colons.  smile

Code:

<script type="text/javascript">
var x=Math.floor(Math.random()*11011) + " People online");
document.write(x);

http://i48.tinypic.com/2z5pqad.png

Offline

 

#5 2012-03-04 16:24:10

poemon1
Scratcher
Registered: 2011-01-12
Posts: 500+

Re: Javascript html compatibility

scmb1 wrote:

poemon1 wrote:

scmb1 wrote:

I'm not an expert on JS, so sorry if I'm wrong, but I think you are missing a ")." Also, maybe there's another way to do it, but I use a "+" instead of a "&" for concatenation.  So...

Code:

<script type="text/javascript">
var x=Math.floor((math.random()*11011)) + "People online")
document.write(x)

Thanks. I'll try it  smile

And you left off the semi-colons.  smile

Code:

<script type="text/javascript">
var x=Math.floor(Math.random()*11011) + " People online");
document.write(x);

Oh yeah...
lol.


http://i47.tinypic.com/rrqe13.gif

Offline

 

#6 2012-03-05 06:43:11

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Javascript html compatibility

Code:

<script type="text/javascript">
var x= Math.floor(math.random()*11011) + " People online";
document.write(x);
</script>

Offline

 

#7 2012-03-05 06:52:41

poemon1
Scratcher
Registered: 2011-01-12
Posts: 500+

Re: Javascript html compatibility

It wont work  sad  I'll download a random people counter. Thanks anayways  smile


http://i47.tinypic.com/rrqe13.gif

Offline

 

#8 2012-03-05 07:12:50

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Javascript html compatibility

Oh yeah, Math.random has to be capitalized.  tongue

Offline

 

Board footer