These are chat archives for FreeCodeCamp/Help

6th
Oct 2018

function translatePigLatin(str) {
  let j = 0;  // counter for words starting with vowel
  const unmodifiedStr = str;
  for (let i = 0; i < str.length; i++) {
    if (str[i] === 'a' || str[i] === 'e' || str[i] === 'i' || str[i] === 'o' || str[i] === 'u') {

      // starts with a vowel (without modifying string)
      if (j === 0) {
        return str + "way";

     // if first index is a vowel (after modifying string)
      } else {
        return str + "ay";
      }

    // if letter is consonant at index 0.
    } else {
      str = str.slice(i+1,str.length) + str.slice(0,1);
      i--;  // return to index 0 until reaching end of str.length
      j = 1;    // to disallow evaluation of first conditional (j === 0) the second time around.
    }
  }

 // exit loop, return if no vowels were found.
  return unmodifiedStr;
}




translatePigLatin("consonant");
what's wrong here
Should handle words with vowels
test not passing
Henry
@GitHub-Henry
Oct 06 2018 06:08
This should help you see what's going on with your code. It will help you walk through your code, step by step. do you have a specific question?
Ai rui 艾瑞
@aisolae
Oct 06 2018 07:34
a collaborator just created a branch, how do i view his works then merge it?
Henry
@GitHub-Henry
Oct 06 2018 07:38
sounds like you need to learn about git to do what you'd like to do
you might be interested in this version of the book
Manish Giri
@Manish-Giri
Oct 06 2018 08:22
@anandpotukchi here's a shorter way of doing that problem using regex -
function translatePigLatin(str) {
  if(/[aeiou]/gi.test(str[0])) {
    return str + "way";
  }
  else {
    let cons = str.match(/[^aieou]+/gi)[0];
    return str.substring(cons.length) + cons + "ay";
  }
}
alpox
@alpox
Oct 06 2018 08:27
@Manish-Giri @anandpotukchi just chiming in:
function translatePigLatin(str) {
  if(/^[aeiou]/.test(str)) return str + "way";
  return str.replace(/^([^aeiou]+)(.*)$/, "$2$1ay");
}
Manish Giri
@Manish-Giri
Oct 06 2018 08:28
function translatePigLatin(str) {
  return (/^[aeiou]/.test(str)) ? str + "way" :  str.replace(/^(.*?)([^aeiou]+)(.*)$/,"$1$3$2ay");
}
might as well go all the way
alpox
@alpox
Oct 06 2018 08:29
I don't like too long lines xD
Aditya Dehal
@aditya2000
Oct 06 2018 12:18
Hello everyone! Is there anyone who can help me with GridFs?
psyperl
@psyperl
Oct 06 2018 12:52
const translatePigLatin = str => 
  str.replace(/^([^aiueo]*)(.*)$/,(m,a,b) => b+(a?a:'w')+'ay')
psyperl
@psyperl
Oct 06 2018 13:04
or
const re = /^([^aiueo]*)(.*)$/
const tpl = (m,a,b) => b+(a?a:'w')+'ay'
const translatePigLatin = s => s.replace(re,tpl)
Andrew Tait Gehrhardt
@atgehrhardt
Oct 06 2018 13:36
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  if (checkObj.hasOwnProperty(checkProp)) {
    return checkProp;
  }
  else {
    return "Not Found";
  }
}

// Test your code by modifying these values
checkObj("gift");
Can anyone help me figure out what I did wrong here. It’s for this lesson https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties/
psyperl
@psyperl
Oct 06 2018 13:37
checkObj.hasOwnProperty(checkProp) <-- ? what is checkObj?
Andrew Tait Gehrhardt
@atgehrhardt
Oct 06 2018 13:39
Ahhh I should be using myObj...
psyperl
@psyperl
Oct 06 2018 13:39
:smile:
Andrew Tait Gehrhardt
@atgehrhardt
Oct 06 2018 13:40
That actually still doesn’t work :/
psyperl
@psyperl
Oct 06 2018 13:40
aww lol
return checkProp; < -- what are you trying to return?
Andrew Tait Gehrhardt
@atgehrhardt
Oct 06 2018 13:42
It returns gfft and pet, but I need it to return pony and kitten
psyperl
@psyperl
Oct 06 2018 13:43
so you got the key and you need the value with that key from the obj yes
Andrew Tait Gehrhardt
@atgehrhardt
Oct 06 2018 13:44
Yeah, ik this is simple but my brain is just hitting a wall here.
psyperl
@psyperl
Oct 06 2018 13:46
acessing a value from the object can be done by subscripting or dot notation
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

// to get "pony" can use
myObj["gift"] // will get "pony"
// or
myObj.gift  // will also get "pony"
// using variable as a subcript
var someVar = "gift"
myObj[someVar] // will also get "pony"
psyperl
@psyperl
Oct 06 2018 13:56
it is confusing at first, but you'll get used to it .. it is something that is being used very often in a program
Andrew Tait Gehrhardt
@atgehrhardt
Oct 06 2018 14:10
Thanks a lot for the help!
psyperl
@psyperl
Oct 06 2018 14:11
:+1:
Andrew Tait Gehrhardt
@atgehrhardt
Oct 06 2018 14:41
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  if (myObj.hasOwnProperty(checkProp)) {
    return myObj.checkProp;
  }
  else {
    return "Not Found";
  }
}

// Test your code by modifying these values
checkObj("gift");
This is what I ended up with and still can’t get it to work. I’m trying to get the function to return the value of whatever it is given from myObj
Andrew Tait Gehrhardt
@atgehrhardt
Oct 06 2018 14:47
I got it to work by changing
return myObj.checkProp;
To
return myObj[checkProp];
can anyone explain why one works and the other doesn’t. In this case shouldn’t they function the exact same way.
Aditya
@ezioda004
Oct 06 2018 14:55
@atgehrhardt dot notation only works for strings, since checkProp is a variable, you'll need to use bracket notation.
Andrew Tait Gehrhardt
@atgehrhardt
Oct 06 2018 14:55
Ahhhhhh wow, I feel quite dumb -.- thanks a lot!
psyperl
@psyperl
Oct 06 2018 14:55

myObj.checkProp doesn't work because there is no key by the name 'checkProp' in myObj
myObj[checkProp] works because the value of checkProp is a string 'gift'
so
myObj.checkProp is equivalent to myObj['checkProp']
and
myObj[checkProp] is equivalent to myObj['gift'] when checkProp is set to 'gift'

some tricky code below to test understanding

myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
}

var pet = "gift"

myObj[pet] // gives "pony"
myObj['pet'] // gives "kitten"
myObj.pet // gives "kitten"
Andrew Tait Gehrhardt
@atgehrhardt
Oct 06 2018 15:11
@psyperl This makes a ton more sense. Thanks for the clarification. I totally missed this diffrentiation in the associated lesson for this.
psyperl
@psyperl
Oct 06 2018 15:12
@atgehrhardt awesome
May Kittens Devour Your Soul
@diomed
Oct 06 2018 17:27

hah! peasants
Aditya
@ezioda004
Oct 06 2018 17:42
🤖 :thought_balloon:
Aita Kane
@aita-kane
Oct 06 2018 18:38
Hello I have a project to submit at October 23rd (php framework) . Our teacher taught us the CodeIgniter framework and for the exam we have to use a different one . So I was wondering which framework will be easy to understand like CodeIgniter . Do you think that I can understand Laravel in this short term? Thank for all advices
Nicolas Ramirez
@kamatheuska
Oct 06 2018 20:36
@diomed lol
Lance
@texas2010
Oct 06 2018 20:42
@diomed hi
Karma Drukpa
@coderkarma
Oct 06 2018 23:16
@ kyle
Are you online?