Old 12-26-2008, 05:47 PM   #1 (permalink)
Cloud's Hair Spray
 
Join Date: Dec 2008
Location: At home, stalker
Posts: 66
Reputation: 11
Default Java script question

Im trying to do this problem to find the largest palindrome made by multiplying two 3-digit numbers

Link: http://projecteuler.net/index.php?section=problems&id=4

Anyhoo, can some one tell me what's wrong with this line:

pal2=pal1.charAt(5)+pal1.charAt(4)+pal1.charAt(3)+ pal1.charAt(2)+pal1.charAt(1)+pal1.charAt(0)

im getting an incompatible types error....

Last edited by davidnvn; 12-26-2008 at 06:28 PM.
davidnvn is offline  
Old 12-26-2008, 09:54 PM   #2 (permalink)
Crumbly, but Good
 
Eriond's Avatar
 
Join Date: May 2006
Location: Montreal
Posts: 1,618
Reputation: 57
Send a message via MSN to Eriond
Default

I'm not really familiar with JavaScript, but uh... it seems to me you're using a string where you should be using an int.

pal1.charAt is going to return a character. Adding the character value (If the character is '9', the character value is 57) to the other character values will give you some random number. (I don't know why you'd want to have this line in your program)

Anyway, if pal2 is a string, and you're trying to make it equal to an integer, it's not going to work (at least in JavaScript, I think. There might be some weird toString stuff going on, but, I dunno.).

It's like saying

String1 = 45

I don't think it'll work. Try wrapping it in String( ). i.e. pal2=String(pal1.charAt(5)+pal1.charAt(4)+pal1.cha rAt(3)+ pal1.charAt(2)+pal1.charAt(1)+pal1.charAt(0))
__________________
Outsider
3D Space Action Shooter/RPG in Development
http://www.youtube.com/user/outsidergame
Eriond is offline  
Old 12-26-2008, 10:26 PM   #3 (permalink)
Cloud's Hair Spray
 
Join Date: Dec 2008
Location: At home, stalker
Posts: 66
Reputation: 11
Default

I changed it completely, so I didn't need this question anymore

Thanks, though, that would've helped alot
davidnvn is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:41 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.0
OnRPG, Copyright ©2003-2011, Game Entertainment Enterprises