Solution 1 :

(1, word.length) doesn’t do what you think. What you have here is the comma operator called on 1 and word.length, surrounded by parentheses, which don’t do much here since there are no other parts to this expression. This operator evaluates all its operands, and returns the last one, which is word.length.

In seems as though you meant to extract the substring of the word:

restofword = word.substring(1, word.length);

Which could also be shortened to

restofword = word.substring(1);

Problem :

I am trying to get it so that the result is the rest of the word + first letter + ‘ay’; right now my code is giving me the total number of letters + first letter + ‘ay’. I believe my third variable is what is causing this to happen but I don’t know how to fix it.

function PigLatin()
// assumes: word is given by user
// results: word reshaped in piglatin
  var word, firstletter, restofword

  word = document.getElementById('wordbox').value;
  firstletter = word.charAt(0);
  restofword = (1, word.length);

  document.getElementById('outputDiv').innerHTML = (restofword + firstletter + 'ay');
<h1>Pig Latin</h1>
<p>What is your word? <input type="text" id="wordbox" value="" ;></p>
<input type="button" value="Click here to convert" onclick="PigLatin();">
<div id=outputDiv></div>


Comment posted by takendarkk

What are you expecting

Comment posted by String#slice

it looks like, you are looking for

Comment posted by comma operator

Now you just have a

Comment posted by Heretic Monkey

Please pay attention when tagging. This question has nothing to do with Apache Pig, and nothing to do with Latin. It really doesn’t have to do with pig Latin. That just happens be the exercise you’re doing.

Comment posted by mplungjan

restofword = word.substring(1, word.length);