|
|
#1 (permalink) |
|
Cloud's Hair Spray
Join Date: Dec 2008
Location: At home, stalker
Posts: 66
Reputation: 11
|
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. |
|
|
|
|
#2 (permalink) |
|
Crumbly, but Good
|
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))
__________________
|
|
|
| Thread Tools | |
| Display Modes | |
|
|