Pig Latin Translator Bug | JS

I am making a pig latin translator, but when you type “chess” it gives you “cesscha” instead of “esscha”, I cannot find the bug, Please help. Here is the code:

var word = "chess";
console.log(word)
if (word[0] == "c") {
  if (word[1] == "h") {
    const translate = word.replace(word[0], "") && word.replace(word[1], "") + word[0] + word[1] + "a";
    console.log(translate)
  } else {
    const translate = word.replace(word[0], "") + word[0] + "a";
    console.log(translate)
  }
} else {
    const translate = word.replace(word[0], "") + word[0] + "a";
    console.log(translate)
}

Hi there and welcome to the forum!

I have edited your post to make your code legible. If you wish to post code on the forum, please use the Preformatted Text tool (</> icon or CTRL+e) to create two sets of backticks between which you can paste your code.

Thank You Everybody For Helping Me, I No Longer Need Help. Thank You!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.