Not a function. Undefined

Tell us what’s happening:
Describe your issue in detail here.
Hello guys I just want some clarification
Why does the console results say str.shift is undefined. What is the logic behind it and what do I need to change

  **Your code so far**

function translatePigLatin(str) {
let conso = /^(aeiou)/;
if(conso.test(str) === false){str.shift()
return str;

  **Your browser information:**

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1

Challenge: Pig Latin

Link to the challenge:

Is shift defined on a string?

I’d just use a word here rather than some abbreviation of sorts.

What do you mean defined on a string

Shift is a built in function for arrays, not strings

1 Like

Ohhhhh yes thank you. It’s annoying how such small details can escape me and I remain stuck. Thank you

yeah it happens sometimes, make sure to always re-read everything, there couldbe something you missed

Strings are immutable, shift mutates the data it is called on. The two are incompatible. All string methods that make a change to the string return a new string.

let word = "hello"
console.log(word[0]) // 'h'

word[0] = 'a'
console.log(word) // 'hello'
1 Like

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