• HuntressHimbo@lemm.ee
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    6 months ago

    Hi, I don’t think giving you the answer directly will help you learn it, but I can give you some general tips for this.

    First here is the MDN documentation for the string type: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

    On the left hand side you should see a column with methods the string type contains. You can use several of these to accomplish a palindrome check. String.slice(), String.charAt(), String.at(), String.match(), and String.substring() are all methods that you can use to write your check.

    In addition to those, I would recommend looking at String.toLowerCase()/String.toUpperCase() to avoid issues with capitalization, and String.trim() to avoid trailing or leading whitespace.

    Also you will need a variable to store your result, my general recommendation is to start this variable as true and set it to false when you detect any inconsistency, and probably one to store the index you are currently checking. Last little tip is that many String methods accept negative indices to count from the end rather than from the start. Good luck!

    One more giant tip because I don’t know what your experience with JavaScript is, but pay attention when comparing that you don’t use == when you should use === and vice versa. The difference is that == will try to coerce the values to the same type before comparison, which can lead to.unintuitive behavior