Jump to content

Variable type? I duuno,


Lae.
 Share

Recommended Posts

Ok, this is the first javascript I have ever written. I took one course in java and then read for a couple hours on javascript. Here is the problem fuction:

function intialize(){ numberOfPics = 3  slotOneInt = createRandomNumber(1, numberOfPics)  // Returns a number  slotOneTime = createRandomNumber(2, 5) * 1000      //  Returns a number  var sourceName = sourceGenerator(slotOneInt)          //  Returns a string  document.slotOne.src = "sourceName" //timer()
So if I set document.slotOne.src = "sourceName" as document.slotOne.src = "pic2.jpg" or whatever it works. If I use the variable, which I have tested with 'typeof' and is a string it doesn't work. What's up with this?The sourceGenerator(anInt) function works. I tested it. It returns a string of the proper description. ie. "picSomeRandomNumber.jpg"Seriously I have sat on this for days thinking and reading. lol This is hurt'n. Why can't I use a string variable, but I can use a string?I am by no means an ace, I did one java course a year ago and that's it for my programing experience. Currently the script excutes with no errors, if you want to see the whole thing or know what it actually does just ask. Thanks a bunchLae.
Link to comment
Share on other sites

You might wanna set the id of slot1 to "slot1" and then use this script:

function intialize(){ numberOfPics = 3  slotOneInt = createRandomNumber(1, numberOfPics)  // Returns a number  slotOneTime = createRandomNumber(2, 5) * 1000      //  Returns a number  var sourceName = sourceGenerator(slotOneInt)          //  Returns a string  document.getElementById("slot1").src = sourceName//timer()

Link to comment
Share on other sites

Thanks Chocolate. your dilly there works. Is there an API I can look at for javascript? Or a decent refference somewhere? I want to ask about an IDE too.. I mean most people laugh at the idea... but I type like a like I am drunk. So auto completes, and highlighting un-instantiated variables (AKA mispelled) and such is a big bonus. (o:Also do you guys look at scripts and critique them? Or is this not the place for that?lol sorry guys, I spent years tapping out HTML in notepad! I've had enough of that pain. Anyway, Thanks for n00b orientation 101 here. (o:Lae.

Link to comment
Share on other sites

Lol, don't worry about being a newbie, i probably know as much as you. :)Sure, post your scripts here. Except, try to keep them in as little topics as possible. ~Chocolate570

Link to comment
Share on other sites

I just meant that if you have more than one script that you want critiqued, then post them in the same topic, don't make like 6 new topics. It's just easier to read. I'm not saying you've done it so far. :)

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
 Share

×
×
  • Create New...