I have deployed a small project to netlify.
the project consist of an html file and JS file.
some of the js functions work correctly, but theres several that dont work at all.
locally with live server everything is fine
why possibly is this happening?
I used netlify a lot and so far i havent stumbled such a problem
perry
June 7, 2022, 5:02pm
2
hi there,
cute project! i like it.
are you having any build errors at all?
no
locally with live server everything is perfect
(console is empty of errors)
@pocketGod This was an interesting one to debug.
You’re doing a substring of the image src
to determine what move the player made, trying to access p
, r
, s
.
The image src is specified as pic/p.png
, pic/r.png
, pic/s.png
which is only 9 characters, (but it gets returned as the full url).
If you select a move and do a check in the console for currentMove
it reveals:
Which is obviously longer than you’re anticipating.
Doing the substring on it reveals:
The computer move is the same:
Your code isn’t expecting a y
, and doesn’t handle it:
As there’s no match and it doesn’t throw an error, it just fails silently.
1 Like
first of all - thank you very much for taking the time to try and help me
regarding your solution - actually i am not receiving “y” in any case - at least not locally on live server.
are you suggesting that the outcome of lines 37,38 are different between local live server and netlify server?
That’s because your local server isn’t at https://rps-by-aviv.netlify.app
You can check for yourself, open the site at https://rps-by-aviv.netlify.app , select a move, open your console, type currentMove.substring( 26, 27 )
and hit enter.
you are right
i have made the following change and the console indeed writes the message
now im wondering if my approach with the src comparison was wrong
thank you very much
so the solution is to change the values of the substring method? wont that make the script not work locally?
That would be one solution, but you’re right that it would make it not work locally.
A better option would be to find another way to identify what has been selected.
There are lots of ways that you could do this, for example determining which move it is in your 'click'
handler and storing the actual move (not the src).
You could also use data attributes as an easy way of setting a value against each element.
i will look into it
thanks again for your help
much appreciated
1 Like