These are chat archives for FreeCodeCamp/HelpJavaScript

22nd
Mar 2017
Aaron Bell
@awb715
Mar 22 2017 00:00
yeah i can fix that
the page loads slow
monkeyfingerz
@monkeyfingerz
Mar 22 2017 00:00
@siddarthk123 the best way to get help on this forum is just to post your problem
and someone will respond if they can help
turbit-smart
@turbit-smart
Mar 22 2017 00:00
@monkeyfingerz oh dam i went crazy because of that i knew i wrote everything and that my mistake in something so small :( thanks
CamperBot
@camperbot
Mar 22 2017 00:00
turbit-smart sends brownie points to @monkeyfingerz :sparkles: :thumbsup: :sparkles:
:cookie: 246 | @monkeyfingerz |http://www.freecodecamp.com/monkeyfingerz
Pieter Stokkink
@forkerino
Mar 22 2017 00:00
@siddarthk123 you are returning the wrong thing!
@siddarthk123 and .shift() doesn't take an argument
.shift() returns the element it removes. (that is useful info)
Siddarth Krishnan
@siddarthk123
Mar 22 2017 00:03
so
add the number to he end of the array.
which would be.
arr.push(item);
right?
Pieter Stokkink
@forkerino
Mar 22 2017 00:03
@siddarthk123 that part was correct
Siddarth Krishnan
@siddarthk123
Mar 22 2017 00:03
then remove the first element of the array.
arr.shift();
right?
Pieter Stokkink
@forkerino
Mar 22 2017 00:04
yes, but you should do something with the value this thing returns.
Siddarth Krishnan
@siddarthk123
Mar 22 2017 00:05
return arr.shift()?
Pieter Stokkink
@forkerino
Mar 22 2017 00:05
bingo!
Siddarth Krishnan
@siddarthk123
Mar 22 2017 00:06
that's not right
now i got

function nextInLine(arr, item) {
// Your code here
arr.push(item);
arr.shift();

return arr.shift(); // Change this line
}

Pieter Stokkink
@forkerino
Mar 22 2017 00:06
@siddarthk123 you should only have one .shift()
Siddarth Krishnan
@siddarthk123
Mar 22 2017 00:06
It's not letting me completed the challenge.
Pieter Stokkink
@forkerino
Mar 22 2017 00:06
now you remove 2 elements
@siddarthk123 did it work?
Pieter Stokkink
@forkerino
Mar 22 2017 00:12
I'm going to :zzz: Good night everyone!
forkerino @forkerino dreams of electric :sheep:
Stephen James
@sjames1958gm
Mar 22 2017 00:15
@forkerino Are you an android?
Thom
@klondikepanther
Mar 22 2017 00:19
I am having some trouble identifying some palindromes my code works for all the requirements except "almostomla" I am stuck any feel like taking a look at my code?
function palindrome(str) {
  // Good luck!
  str = str.toLowerCase();
  var compairArray = [];
  var strArrayKeep = [];
  var revStrArray =[];
  var finalArray = [];
  var strArray =[];
  var newStr = str.replace(/\W/g, '');
  newStr = newStr.replace(/[_-]/g, ""); 
  strArray = newStr.split("");
  revStrArray = strArray.slice().reverse();
 for (i=0; i<revStrArray.length; i++)
   compairArray[i] = revStrArray[i] + strArray[i];
 for(i=0; i<compairArray.length; i++)
  finalArray[i] = compairArray[i].split("");
  for(i=0; i<finalArray.length; i++)
    for(j=0; j<finalArray[i][j].length; j++)
    if (finalArray[i][j] !== finalArray[(i)][j+1]){return false;}else{return true;}
}
Roxroy
@roxroy
Mar 22 2017 00:29
@klondikepanther , though your code works you may want to simplify to so that you can follow it.
So basically, you would take newStr and split it().
Then take the split array and reverse it.
You can then join the newStr and join the newStr.reverse.
Then compare each one to see if they match each other.
Stephen James
@sjames1958gm
Mar 22 2017 00:30
@klondikepanther You have revStrArry - if you join("") you will have a string which you can compre to newStr
James
@jamesns
Mar 22 2017 00:37
hey guys. i'm having a hard time with the "Falsy Bouncer" challenge, can't get passed it. could someone please shed some light on the problem?
function bouncer(arr) {
  for (i = 0; i < arr.length; i++) {
    if (Boolean(arr[i]) === false ) {
        arr.splice(i, 1);
    }
  }
return arr;
}

bouncer([1, null, NaN, 2, undefined]);
Stephen James
@sjames1958gm
Mar 22 2017 00:46
@jamesns splice inside of for loop is not the best. If you must do that use i-- inside the splice to reduce i because of the removed element
@jamesns My preference and accepted practice is to not modify the input arr but create a new array for output.
create a new empty array and then push the true values onto it
James
@jamesns
Mar 22 2017 00:48
@sjames1958gm got it, I'll try that. thank you !
CamperBot
@camperbot
Mar 22 2017 00:48
jamesns sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 6278 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Thom
@klondikepanther
Mar 22 2017 00:50
@roxroy holy crap I way over complicated that thanks
CamperBot
@camperbot
Mar 22 2017 00:50
klondikepanther sends brownie points to @roxroy :sparkles: :thumbsup: :sparkles:
:cookie: 431 | @roxroy |http://www.freecodecamp.com/roxroy
Thom
@klondikepanther
Mar 22 2017 00:51
@sjames1958gm Thank you! I way over complicated that
CamperBot
@camperbot
Mar 22 2017 00:51
klondikepanther sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 6279 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Mar 22 2017 00:51
@klondikepanther :+1:
@jamesns gl
Saboor Malik
@MathematicsCoding
Mar 22 2017 00:58
Sigh
@sjames1958gm do you know objective c/swift?
Stephen James
@sjames1958gm
Mar 22 2017 00:58
@MathematicsCoding I do not
Saboor Malik
@MathematicsCoding
Mar 22 2017 00:59
Ok
I have been trying to learn these languages by online...
All the sites i have visited costs...
Joseph
@revisualize
Mar 22 2017 01:00
Hi
Jaco Ahmad
@jacoahmad
Mar 22 2017 01:00
Objective C is a language for iOS isnt? @MathematicsCoding
Sup @revisualize
Joseph
@revisualize
Mar 22 2017 01:01
Chillin'
Saboor Malik
@MathematicsCoding
Mar 22 2017 01:02
@jacoahmad Yes it is
@jacoahmad Do you know them?
Jaco Ahmad
@jacoahmad
Mar 22 2017 01:04
@MathematicsCoding not really, but my friends works for iOS Developer and told me about it
Saboor Malik
@MathematicsCoding
Mar 22 2017 01:05
Oh I see
Do you know where to learn them?
drinkwaterman
@drinkwaterman
Mar 22 2017 01:05
Can anybody spot the mistake in the code below?
It code works fine, everything is green except the last one is red
 var numberOne = 0;
    var numberTwo = 1;
    var sum = 0;
    var fab = [1];

    if (num == 1) {
      return 1;
    }

    //Fabonnaci Numbers
    for (var i = 0; i < num; i++) {  
        sum = numberOne + numberTwo;
        fab.push(sum);
        numberOne = numberTwo;
        numberTwo = sum;
    }

    //OddFab
    var odd = fab.filter(function(val) {
        return val < num && val % 2 !== 0;
    });

    //Sum
    var result = odd.reduce(function(previousVal, currentVal) {
        return previousVal + currentVal;
    });

    return result;
Saboor Malik
@MathematicsCoding
Mar 22 2017 01:07
How do I make a button so I can go somewhere to different link from that button?
Salomon
@zarruk
Mar 22 2017 01:10
https://codepen.io/zarruk/pen/Mprvbd?editors=0011 Hello. How can I do to make that when computed plays, not all the lights turn on at the same time but one at a time (say, every one second)? Please help
dpugachev
@dpugachev
Mar 22 2017 01:14
```
let hello = "   Hello, World!  ";
let wsRegex = /^\s+\s+$/; // Change this line
let result = hello.replace(wsRegex, ""); // Change this line
anyone know why this doesn't remove the white space in start and end?
Jake
@jakekoontz
Mar 22 2017 01:15
can someone explain console.log never called? my code looks correct but i dont understand the message. Thanks!
jordan-r-b
@jordan-r-b
Mar 22 2017 01:18
I am stuck on the Fibonacci challenge. I am getting greens for everything except for "sumFibs(75024) should return 60696" and I have no idea how that's
possible.
Dana Aljirudi
@DanaJirudi
Mar 22 2017 01:19
Hello guys. Can you help me with "Confirm the Ending" Algorithm challenge? I have this so far assuming that the program will only check the last letter.. What should I do to make it check for all letters in target?

function confirmEnding(str, target) {

  var subStr = str.substring(str.length - 1);
  if(subStr === target){
    return true;
  } else{
  return str;
  }
}

confirmEnding("Bastian", "n");
Oh I have a typo.. The second return should return false.. but I still need help>
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:21
i need help with this
i just dont get it what it means?:
var myStr"FirstLine\n\"SecondLine\rThirdLine";
mikemorancodes
@mikemorancodes
Mar 22 2017 01:22

Hey guys. What's wrong with this exactly? It's just not working:

function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch (val)
{
case val==1: answer = "alpha";
break;
case val==2: answer = "beta";
break;
case val==3: answer = "gamma";
break;
case val==4: answer = "delta";

}

// Only change code above this line
return answer;
}

// Change this value to test
caseInSwitch(0);

Roxroy
@roxroy
Mar 22 2017 01:22
@DanaJirudi , search from the end of the string using lastIndexO function
Moisés Man
@moigithub
Mar 22 2017 01:22
@DanaJirudi ur code only checking last character...
"Bastian" ends on "on" should be false
"Bastian" ends on "oan" should be false
"Bastian" ends on "oian" should be false
dpugachev
@dpugachev
Mar 22 2017 01:23
@sdjjr3296 you need to follow the instructions in the problem what did you try?
Dan Couper
@DanCouper
Mar 22 2017 01:23
@DanaJirudi You can find out the length of target...
Dana Aljirudi
@DanaJirudi
Mar 22 2017 01:23
Yes guys give me a minute I think a figured it out
@djnanas That's what I was thinking :smile: Thank you!
CamperBot
@camperbot
Mar 22 2017 01:23
danajirudi sends brownie points to @djnanas :sparkles: :thumbsup: :sparkles:
:cookie: 264 | @djnanas |http://www.freecodecamp.com/djnanas
drinkwaterman
@drinkwaterman
Mar 22 2017 01:25
@jordan-r-b The same here man LOL
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:25
@dpugachev i tried everythimg changing the letters around and abbrivations but i dont just get it
it says to Assign the following three lines of text into the single variable myStr using escape sequences.
but i dont get it since it already have the symbols for it
dpugachev
@dpugachev
Mar 22 2017 01:25
do you have the link to the problem?
or the name of it
Dana Aljirudi
@DanaJirudi
Mar 22 2017 01:25
@DanCouper @moigithub @roxroy I figured it out.. Thank you all for responding :+1:
CamperBot
@camperbot
Mar 22 2017 01:25
danajirudi sends brownie points to @dancouper and @moigithub and @roxroy :sparkles: :thumbsup: :sparkles:
:cookie: 559 | @dancouper |http://www.freecodecamp.com/dancouper
:cookie: 433 | @roxroy |http://www.freecodecamp.com/roxroy
:star2: 2888 | @moigithub |http://www.freecodecamp.com/moigithub
Gulsvi
@gulsvi
Mar 22 2017 01:26
@drinkwaterman Check your fab array, you have some very large numbers in it. I think you need to check that your sum < num before pushing anything to the array.
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:26
@dpugachev Escape Sequences in Strings
its the challege name
Roxroy
@roxroy
Mar 22 2017 01:26
@mikemorancodes , which challenge r u stuck with?
@sdjjr3296 , let me see what you have done so far?
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:27
@roxroy i just reset it
dpugachev
@dpugachev
Mar 22 2017 01:28
@sdjjr3296 so first get rid of all the quotes in the middle, then remember to add an extra \ for every literal \ you need, so \ = \
drinkwaterman
@drinkwaterman
Mar 22 2017 01:28
@SkyCoder01 I tried, but it still doesn't work
if (sum < 100000000) {
          fab.push(sum);
        }
Roxroy
@roxroy
Mar 22 2017 01:28
@sdjjr3296 , use the guide at the side to help guide you
Gulsvi
@gulsvi
Mar 22 2017 01:28
@drinkwaterman Actually, you can pass the challenge by modifying your filter function, since you seems to know that your array is too big already :p that's why you added return val < num I'm guessing.
dpugachev
@dpugachev
Mar 22 2017 01:29
\ = \ I mean
lol
Gulsvi
@gulsvi
Mar 22 2017 01:29
The last case isn't passing because the val = num and you just need to add that one more
dpugachev
@dpugachev
Mar 22 2017 01:29
wtf it's not showing up
\ = \\
Roxroy
@roxroy
Mar 22 2017 01:29
@mikemorancodes , did you get it working?
Gulsvi
@gulsvi
Mar 22 2017 01:30
@drinkwaterman Run the number for that last test case and you'll see you get 60696 back, but you should be getting 135721. 135721 - 60696 = 75025
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:33
@dpugachev i still dont understand
why is not working
Filip
@Entrepreneurteen
Mar 22 2017 01:33
guys help plese a little
please*
Roxroy
@roxroy
Mar 22 2017 01:34
@Entrepreneurteen , what up what challenge are u on.
Filip
@Entrepreneurteen
Mar 22 2017 01:34
Storing Values with the Assignment Operator
i need helkp to asign a to b
a should be assigned to b with =
what about
Filip
@Entrepreneurteen
Mar 22 2017 01:36
@roxroy a should be assigned to b with =
Alejandro Guerra
@GuerraAlejo0821
Mar 22 2017 01:36
tribute page challange
Filip
@Entrepreneurteen
Mar 22 2017 01:36
nice i love the way you curved the picture
drinkwaterman
@drinkwaterman
Mar 22 2017 01:36
@SkyCoder01 Thank you so much man! yes Val should be < or = to num that worked !
CamperBot
@camperbot
Mar 22 2017 01:36
drinkwaterman sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
:cookie: 624 | @skycoder01 |http://www.freecodecamp.com/skycoder01
Roxroy
@roxroy
Mar 22 2017 01:37
@Entrepreneurteen , you would set b to the value of a. Do you know how to do that
Gulsvi
@gulsvi
Mar 22 2017 01:37
@drinkwaterman Congrats :) you were so close!
drinkwaterman
@drinkwaterman
Mar 22 2017 01:37
Yep :D
dpugachev
@dpugachev
Mar 22 2017 01:37
@sdjjr3296 what did you try this time?
Filip
@Entrepreneurteen
Mar 22 2017 01:38
no
spencerjstewart
@spencerjstewart
Mar 22 2017 01:38
I just finished all of the basic algorithm challenges! :)
Filip
@Entrepreneurteen
Mar 22 2017 01:38
@roxroy what do you mean no
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:38
@dpugachev i tried putting the middle with \ both sides of it while taking the qutoes off of it
dpugachev
@dpugachev
Mar 22 2017 01:38
copy paste it
Roxroy
@roxroy
Mar 22 2017 01:39
@Entrepreneurteen , to set the value of b to a you use b = a;
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:39
@dpugachev var myStr"FirstLine\n\SecondLine\rThirdLine";
it wont show the other line
i mean backlash
dpugachev
@dpugachev
Mar 22 2017 01:40
you need to follow this guideline FirstLinenewlinebackslashSecondLinebackslashcarriage-returnThirdLine
and replace blackslash with two \
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:41
but do i have to write it out?
the new line?
dpugachev
@dpugachev
Mar 22 2017 01:41
no of course not
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:41
or such
dpugachev
@dpugachev
Mar 22 2017 01:41
those you already have right
but the backlashes are what's not right
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:41
i tried everything already
ooh ok'
what should i do
dpugachev
@dpugachev
Mar 22 2017 01:42
you need to add double backlashes in the right places
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:42
between the second lines?
dpugachev
@dpugachev
Mar 22 2017 01:42
yes
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:43
this one right? \
dpugachev
@dpugachev
Mar 22 2017 01:43
but need two of them in the source code for every one that's in the literal string
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:44
im not catchign on with the literal string and stuff
dpugachev
@dpugachev
Mar 22 2017 01:44
the source code is what you put in, then I call the literal string, what comes out
so if you want to have one backlash in the string output, you need to have two backlashes in the code
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:45
okay let me try
still not workin :worried:
dpugachev
@dpugachev
Mar 22 2017 01:47
what have you got?
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:48
var myStr"FirstLine\n\SecondLine\\rThirdLine";
Ayush Bahuguna
@relentless-coder
Mar 22 2017 01:49
@sdjjr3296 \ in javascript signifies escaping a special character. which means you want a special character to be included in the output if javascript would try to make it's own sense. so you want \ before SecondLine and after it, so you'd want this \\ before and after SecondLine since you are trying to have \ in the string, in other words, you want javascript compiler to escape it
Luke
@luke818h
Mar 22 2017 01:49
I am a little confused on the madlibs instructions
Ayush Bahuguna
@relentless-coder
Mar 22 2017 01:49
what is it
dpugachev
@dpugachev
Mar 22 2017 01:49
^
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:49
@relentless-coder thats what exactly been doing!!
Ayush Bahuguna
@relentless-coder
Mar 22 2017 01:49
@sdjjr3296 no
dpugachev
@dpugachev
Mar 22 2017 01:49
you only have one backlash
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:50
i put two it wont show up in this chat
Zach Beasley
@beasleyz
Mar 22 2017 01:50
On the repeat a string challenge, are we not able to use recursion?
dpugachev
@dpugachev
Mar 22 2017 01:50
use to put your code here use ```
click the M arrow down button to the right bottom of this chat
Saboor Malik
@MathematicsCoding
Mar 22 2017 01:51
'''
code
'''
CamperBot
@camperbot
Mar 22 2017 01:51
:bulb: to format code use backticks! ``` more info
dpugachev
@dpugachev
Mar 22 2017 01:51
it will tell you how to add code properly here
Saboor Malik
@MathematicsCoding
Mar 22 2017 01:51
Use ``` instead
'''
code
'''
CamperBot
@camperbot
Mar 22 2017 01:51
:bulb: to format code use backticks! ``` more info
Ayush Bahuguna
@relentless-coder
Mar 22 2017 01:51

@sdjjr3296 if this is what your code

var myStr = "FirstLine\n\\SecondLine\\\rThirdLine"

then you are doing right, and it's some technical fault, if not, then you really need to read people's answers a couple of times before freaking out

dpugachev
@dpugachev
Mar 22 2017 01:51
it was always the console command for FPS games
you're missing one backlash there @relentless-coder
Saboor Malik
@MathematicsCoding
Mar 22 2017 01:52
@relentless-coder can you help me with this challenge?
Ronald Johnson
@ronnieg1988
Mar 22 2017 01:52

// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here

  myObj.hasOwnProperty("gift");
  myObj.hasOwnProperty("pet");
  myObj.hasOwnProperty("house");
  return myObj.hasOwnProperty();
}

// Test your code by modifying these values
checkObj("gift");
dont think return value is right
Stephen James
@sjames1958gm
Mar 22 2017 01:52
@relentless-coder That is missing one \ there should be 6 \
dpugachev
@dpugachev
Mar 22 2017 01:52
var myStr = "FirstLine\n\\SecondLine\\\rThirdLine";
Ayush Bahuguna
@relentless-coder
Mar 22 2017 01:52
edited it :)
@MathematicsCoding what is it?
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:53
@dpugachev @relentless-coder the = was the problem xD
Stephen James
@sjames1958gm
Mar 22 2017 01:53
@ronnieg1988 You should be using checkProp and you need an if to check the result of hasOwnProperty
Zach Beasley
@beasleyz
Mar 22 2017 01:53

Has anyone had been able to pass the challenges using recursion?

I tried to use it for repeat a string, and my code producing the correct outputs but not passing the tests.

Saboor Malik
@MathematicsCoding
Mar 22 2017 01:53
This challenge: Make Object Properties Private
Stephen James
@sjames1958gm
Mar 22 2017 01:53
@beasleyz factorial
dpugachev
@dpugachev
Mar 22 2017 01:53
forgot the = ? lol
Saboor Malik
@MathematicsCoding
Mar 22 2017 01:53
Want to see my code
Ayush Bahuguna
@relentless-coder
Mar 22 2017 01:53
yes
Stephen James
@sjames1958gm
Mar 22 2017 01:53
@beasleyz recursion should be allowed.
Zach Beasley
@beasleyz
Mar 22 2017 01:53
Thanks @sjames1958gm
CamperBot
@camperbot
Mar 22 2017 01:53
beasleyz sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 6280 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
dpugachev
@dpugachev
Mar 22 2017 01:53
I always spend hours on little mistakes like that @sdjjr3296
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:53
@dpugachev @relentless-coder thx you
CamperBot
@camperbot
Mar 22 2017 01:53
sdjjr3296 sends brownie points to @dpugachev and @relentless-coder :sparkles: :thumbsup: :sparkles:
:cookie: 199 | @dpugachev |http://www.freecodecamp.com/dpugachev
:cookie: 369 | @relentless-coder |http://www.freecodecamp.com/relentless-coder
Saboor Malik
@MathematicsCoding
Mar 22 2017 01:53

var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};

var Bike = function() {
var gear = 5;

this.getGear = function(change) {
  gear += change;
};

this.setGear = function() {
  gear -=1;
};

};
var myBike = new Bike();
Stephen James
@sjames1958gm
Mar 22 2017 01:54
@MathematicsCoding Compare getGear with getSpeed
Ayush Bahuguna
@relentless-coder
Mar 22 2017 01:54
@MathematicsCoding you don't need gear = 5
Saboor Malik
@MathematicsCoding
Mar 22 2017 01:54
oops...
Jaime Ruelas
@sdjjr3296
Mar 22 2017 01:54
@dpugachev i guess im not only one lol
dpugachev
@dpugachev
Mar 22 2017 01:54
nope :)
Stephen James
@sjames1958gm
Mar 22 2017 01:54
@MathematicsCoding setGear should be like accelerate without the addition only assignment
Alex G
@glazey132
Mar 22 2017 01:54
almighty coders
what's wrong with my code?
function rot13(str) { 
  var output = [];

  for (var j = 0; j < str.length; j++){
  output += str.charCodeAt(j);
  }

  for (var i = 0; i < output.length; i++) {
   if (output[i] >= 65 && output[i] <=90) {
     if (output[i] >= 78) {
       output[i] = (output[i] + 13) - 26;
     }

     else if (output[i] < 78) {
       output[i] = output[i] +13;
     }
   }

    output[i] = String.fromCharCode(output[i]);

  }
  output = output.join("");

    return output;

}                     
// Change the inputs below to test
rot13("SERR PBQR PNZC");
dpugachev
@dpugachev
Mar 22 2017 01:54
you call that code
Alex G
@glazey132
Mar 22 2017 01:54
function rot13(str) { 
  var output = [];

  for (var j = 0; j < str.length; j++){
  output += str.charCodeAt(j);
  }

  for (var i = 0; i < output.length; i++) {
   if (output[i] >= 65 && output[i] <=90) {
     if (output[i] >= 78) {
       output[i] = (output[i] + 13) - 26;
     }

     else if (output[i] < 78) {
       output[i] = output[i] +13;
     }
   }

    output[i] = String.fromCharCode(output[i]);

  }
  output = output.join("");

    return output;

}                     
// Change the inputs below to test
rot13("SERR PBQR PNZC");
Saboor Malik
@MathematicsCoding
Mar 22 2017 01:54
@sjames1958gm okay
Ayush Bahuguna
@relentless-coder
Mar 22 2017 01:55
@MathematicsCoding with set gear you'd set the gear's value, you'd assign a value, no additions or other calculations, then with get gear you just return that valu :)
Stephen James
@sjames1958gm
Mar 22 2017 01:55
@glazey132 Arrays don't have += operator - you could use push - but why not use split instead of the for loop?
Alex G
@glazey132
Mar 22 2017 01:55
im getting a type error. it says cannot assign to read only property '0' of string
Saboor Malik
@MathematicsCoding
Mar 22 2017 01:56

var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};

var Bike = function() {
var gear = 4;
this.getGear = function(change) {
  speed -= 1;
};

this.setGear = function() {
  return gear;
};

};
var myBike = new Bike();
Alex G
@glazey132
Mar 22 2017 01:56
@sjames1958gm you make a great point stephen. let me see what i can come up with quick
dpugachev
@dpugachev
Mar 22 2017 01:56
@glazey132 I don't know if it will help, but Google Console says Uncaught TypeError: output.join is not a function
at rot13 (<anonymous>:22:19)
at <anonymous>:28:1
Zach Beasley
@beasleyz
Mar 22 2017 01:57
var str2 = [];

function repeatStringNumTimes(str, num) {
  if (num <= 0)
    return ("");
  str2 += str;
  if(num > 1)
    repeatStringNumTimes(str, num - 1);
  return str2;
}

repeatStringNumTimes("abc", 3);
Anyone have an idea why my code wouldn't be passing tests?
Brian
@BeardedBry
Mar 22 2017 01:57
Hey all, I'm having a lot of trouble with the Seek and Destroy challenge
Stephen James
@sjames1958gm
Mar 22 2017 01:58
@beasleyz You cannot use globals in most FCC challenges as they are not reset between tests.
Generally recursion is done through the return value
Zach Beasley
@beasleyz
Mar 22 2017 01:58
It has the correct outputs. I'm wondering if I'm just not doing it the way it wants us too to do
Ayush Bahuguna
@relentless-coder
Mar 22 2017 01:58
@MathematicsCoding you don't have to change speed. you need set a value for gear(with setGear()) and return that same value by using getGear()
Zach Beasley
@beasleyz
Mar 22 2017 01:58
Ahhhh, okay cool.
Saboor Malik
@MathematicsCoding
Mar 22 2017 01:58
Wrong code... Here what I got edited
Zach Beasley
@beasleyz
Mar 22 2017 01:58
Many thanks @sjames1958gm
CamperBot
@camperbot
Mar 22 2017 01:58
beasleyz sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: beasleyz already gave sjames1958gm points
Saboor Malik
@MathematicsCoding
Mar 22 2017 01:58
var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};

var Bike = function() {
var gear = 1;
this.getGear = function(change) {
  gear += change;
};

this.setGear = function() {
  return gear;
};

};
var myBike = new Bike();
Stephen James
@sjames1958gm
Mar 22 2017 01:58
@MathematicsCoding getGear should match the pattern that getSpeed has (but for the gear variable)
@beasleyz :+1:
Ayush Bahuguna
@relentless-coder
Mar 22 2017 01:59

@MathematicsCoding

@MathematicsCoding with set gear you'd set the gear's value, you'd assign a value, no additions or other calculations, then with get gear you just return that valu :)

tomas89
@tomas89
Mar 22 2017 01:59
hello
Stephen James
@sjames1958gm
Mar 22 2017 01:59
@MathematicsCoding The names of the functions have meaning.
Alex G
@glazey132
Mar 22 2017 01:59
@sjames1958gm would something like this work better?: var output = charCodeAt(str.split(''));
tomas89
@tomas89
Mar 22 2017 01:59
I can a help me
Stephen James
@sjames1958gm
Mar 22 2017 02:00
@glazey132 var output = str.split(""); then output is an array of characters
@tomas89 What help you need?
KatSaldivar
@KatSaldivar
Mar 22 2017 02:00
I'm not sure how to get these radio buttons working. Do you guys see any mistakes in my code? ```
if(document.getElementById('cel').checked) {
$(".temperature").html(tempCel);
}else if(document.getElementById('far').checked) {
$(".temperature").html(tempFar);
}
    if(document.getElementById('cel').checked) {
$(".temperature").html(tempCel);
    }else if(document.getElementById('far').checked) {
$(".temperature").html(tempFar);
}
tomas89
@tomas89
Mar 22 2017 02:01
its this code
Alex G
@glazey132
Mar 22 2017 02:01
@sjames1958gm that makes sense but then how do you convert the array of characters into corresponding character code without a for loop?
Stephen James
@sjames1958gm
Mar 22 2017 02:02
@glazey132 Oh, the only for loop that removes is that first one. You are correct that you need a loop over output to convert the characgers
tomas89
@tomas89
Mar 22 2017 02:02
<body id="body">
<form method="post" action="something.php" name="myForm" onsubmit="return validateForm()"></form>
<div>
<label>First Name</label>
<input type="text" name="firstName" id="firstName">
</div>
<div>
<label>Last Name</label>
<input type="text" name="lastName" id="lastName" />
</div>
<br/>

<div>
<label>background</label>
<select name="background" id="background" onchange="changeBackground(this)">
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
<option value="black">black</option>
<option value="purple">purple</option>
<option value="pink"></option>
</select>
</div>
<br />
<input type="submit" name="Submit"/>
<script>
function changeBackground(x){
console.log(x.value);
var body = document.getElementById('body');
body.style.background = x.value;
}

function validateForm(){
var firstName = document.forms["myForm"]["firstName"].value;

if(firstName == null || firstName == ""){
alert("first Name is required");
return false;
}

if (firstName.length < 3 ) {
alert("First name must be at least 3 chars");
return false;
}
}
</script>
</body>
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:04
var myBike = function() {


myBike.getGear = function() {
};

myBike.setGear = function() {
  return gear;
};

};
var myBike = new Bike();
How can .getGear return 4 after setGear?
Aaron Fox
@aaronfox
Mar 22 2017 02:05
I've looked at dozens of resources for understanding callback functions, but it's still bending my mind a bit. Does anyone have some good resources/ practice recommendations for callback functions?
Allan Pooley
@AllanPooley
Mar 22 2017 02:05
@KatSaldivar It looks ok to me! Is it possible to see your codepen?
Ayush Bahuguna
@relentless-coder
Mar 22 2017 02:06
@KatSaldivar could you explain what errors are you getting?
dpugachev
@dpugachev
Mar 22 2017 02:06
@aaronfox have you tried googling it?
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:07
@relentless-coder
var myBike = function() {
  var getGear = 4;

myBike.getGear = function() {
  return getGear;
};

myBike.setGear = function() {

};

};
var myBike = new Bike();
Alex G
@glazey132
Mar 22 2017 02:07
@sjames1958gm so would it make sense to do something like this and then iterate thru the codedChars array?
var output = str.split(''); for (var j = 0; j < output.length; j++){ var codedChars = output.charCodeAt(j); }
tomas89
@tomas89
Mar 22 2017 02:08
<script>
function changeBackground(x){
console.log(x.value);
var body = document.getElementById('body');
body.style.background = x.value;
}

function validateForm(){
var firstName = document.forms["myForm"]["firstName"].value;

if(firstName == null || firstName == ""){
alert("first Name is required");
return false;
}

if (firstName.length < 3 ) {
alert("First name must be at least 3 chars");
return false;
}
}
</script>
Moisés Man
@moigithub
Mar 22 2017 02:08
charCodeAt is a string method
but output contains an array @glazey132
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:09
@moigithub
Stephen James
@sjames1958gm
Mar 22 2017 02:09
@glazey132 output is an array - output[j] is a character
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:09
Can you help me?
Ugh someone help me..
Ayush Bahuguna
@relentless-coder
Mar 22 2017 02:09
@MathematicsCoding why is your set gear function empty??
Stephen James
@sjames1958gm
Mar 22 2017 02:09
@MathematicsCoding Try to match the pattern from the example - use the private variable gear
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:10
var myBike = function() {
  var getGear = 4;

myBike.getGear = function(change) {
  getGear -= change;
  return getGear;
};

myBike.setGear = function() {

};

};
var myBike = new Bike();
Stephen James
@sjames1958gm
Mar 22 2017 02:10
@MathematicsCoding You seem to randomly change code without any seeming reason
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:10
@MathematicsCoding why is your set gear function empty??
Thats the reason..
Well I was trying to do the same like an example
Wait...
Stephen James
@sjames1958gm
Mar 22 2017 02:12
@MathematicsCoding getGear - the name implies - returns the gear value - just like getSpeed returns the speed value
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:12
He said set Gear... not get Gear
*Facepalm
var myBike = function() {
  var setGear = 4;

myBike.getGear = function() {

};

myBike.setGear = function(change) {
  setGear -= change;
  return setGear;
};

};
var myBike = new Bike();
KatSaldivar
@KatSaldivar
Mar 22 2017 02:14
@relentless-coder @AllanPooley I want it to display the temp in C or F when its checked. http://codepen.io/KatSaldivar/pen/wJydNv?editors=1111
Alex G
@glazey132
Mar 22 2017 02:14
@moigithub i get that but doesnt iterating through output let you invoke charCodeAt on the chars inside the array?
Victoria Zambrano
@vzambrano98
Mar 22 2017 02:15
sooooo.....working on wikipedia app and I'm having a problem displaying the info. I used a for loop and it's not acutally iterating through my data....it's just using the first values and returning those....can anyone point out what i'm doing wrong?
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:15
Now I messed up this code...
Victoria Zambrano
@vzambrano98
Mar 22 2017 02:16
$('document').ready(function() {


  $('#search-button').on('click', function() {

    var input = $('#input').val();
    var url = 'https://en.wikipedia.org/w/api.php?action=opensearch&search='+input+'&format=json&origin=*';


    $.ajax({
      type:"GET",
      url:url,
      asynch: false,
      datatype:'json',
      success: function(data){
        var title= "";
        var descr= "";
        var link= ""; 
        for(var i=0; i<data.length; i++){
        title= data[i+1][i]; 
        descr=  data[i+2][i]; 
        link=  data[i+3][i];
        $('#output').append ('<li>' + title + ', ' + descr + ', ' + link + '</li>')
        };

      }
    });
  });
});
Allan Pooley
@AllanPooley
Mar 22 2017 02:17
@KatSaldivar I'm still looking, but to start, what helps me find bugs in my code is making sure the indentation is on point! You can hit the down arrow in the top right corner of your JS editor and select 'Tidy JS' and it'll do it for you!
Moisés Man
@moigithub
Mar 22 2017 02:17
the "chars" are string.. but this string is contained inside the array...
soo first u would needto access the array element before (the string)
to be able to apply charCodeAt method on the string itself
:point_up: 21 de marzo de 2017 21:09 @glazey132
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:18
@sjames1958gm Im finally getting what you were trying to saying
To compare like that example
var Bike = function() {
var gear = 4;
  // Only change code below this line.
this.accelerate = function(change) {
    gear += change;
  };

  this.decelerate = function() {
    gear -= 1;
  };
  this.getGear = function() {
    return gear;
  };
  this.setGear = function() {
    return gear;
  };
};
Its return 4 this time
Ayush Bahuguna
@relentless-coder
Mar 22 2017 02:19
@MathematicsCoding no no no
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:19
What...
Stephen James
@sjames1958gm
Mar 22 2017 02:19
@MathematicsCoding setGear what do you think a function called setGear should do?
Victoria Zambrano
@vzambrano98
Mar 22 2017 02:19
@KatSaldivar an easy way to do it for me was this method here: `$('selector').on('click', function()) to show the different data sets when one is clicked vs the other
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:20
I have no idea...
Ayush Bahuguna
@relentless-coder
Mar 22 2017 02:20
@MathematicsCoding you don't read people's answers properly
Stephen James
@sjames1958gm
Mar 22 2017 02:20
@MathematicsCoding Maybe set the gear value?
Victoria Zambrano
@vzambrano98
Mar 22 2017 02:21
@KatSaldivar so when Celcius is clicked XYZ will occur. and when Fahrenheit is clicked XYZ will occur instead....what XYZ is should be up to you
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:21
var Bike = function() {
var gear = 4;
  // Only change code below this line.
  this.getGear = function(change) {
    gear += change;
    return gear;
  };
  this.setGear = function() {
  };
};
KatSaldivar
@KatSaldivar
Mar 22 2017 02:21
@vzambrano98 ty I'll try tgat
CamperBot
@camperbot
Mar 22 2017 02:21
katsaldivar sends brownie points to @vzambrano98 :sparkles: :thumbsup: :sparkles:
:cookie: 267 | @vzambrano98 |http://www.freecodecamp.com/vzambrano98
Stephen James
@sjames1958gm
Mar 22 2017 02:22
@MathematicsCoding getGear should be patterned after getSpeed
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:22
var Bike = function() {
var gear = 4;
  // Only change code below this line.
  this.getGear = function(change) {
    gear += change;
  };
  this.setGear = function() {
    return gear;
  };
};
Keon Samuel
@keonsam
Mar 22 2017 02:22
saboor wrong
Ayush Bahuguna
@relentless-coder
Mar 22 2017 02:22
@MathematicsCoding what does get and set mean in English???
Keon Samuel
@keonsam
Mar 22 2017 02:23
get and set
Alex G
@glazey132
Mar 22 2017 02:23
@moigithub so i feel like im no the right track. tell me if this is a solid though process or not

` var codedChars = [];
var output = str.split('');

//iterate through the array of chars and change them to charCode
for (var j = 0; j < output.length; j++){
var code = output(j);
codedChars.push(charCodeAt(code));
}`

Allan Pooley
@AllanPooley
Mar 22 2017 02:23
@KatSaldivar Yep, thats it, exactly as @vzambrano98 pointed out. You need to have a function to check for the event, as opposed to checking whether the button have been checked once the document has loaded. Also some of your HTML classes are missing quotations (not sure if this will cause issues).
Keon Samuel
@keonsam
Mar 22 2017 02:23
getGear has to do equal to setGear
KatSaldivar
@KatSaldivar
Mar 22 2017 02:24
@AllanPooley TY!
CamperBot
@camperbot
Mar 22 2017 02:24
katsaldivar sends brownie points to @allanpooley :sparkles: :thumbsup: :sparkles:
:cookie: 311 | @allanpooley |http://www.freecodecamp.com/allanpooley
Arvind Lairenjam
@arvind00
Mar 22 2017 02:24
hi everyone, anyone had issue with bootstrap navbar in codepen? How u made it work?
Keon Samuel
@keonsam
Mar 22 2017 02:24
setgear is where the number is input
Allan Pooley
@AllanPooley
Mar 22 2017 02:24
@KatSaldivar Also! you can edit the text in a heading using text() instead of HTML... for example: $(".temperature").text(tempCel + "dC");
Stephen James
@sjames1958gm
Mar 22 2017 02:24
@glazey132 if output[j] is a character then output[j].charCodeAt(0) is the character code
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:24
var Bike = function() {
var gear = 4;
  // Only change code below this line.
  this.getGear = function(change) {
    gear += change;
    return gear;
  };
  this.setGear = function(change) {
    gear += change;
    return gear;
  };
};
Keon Samuel
@keonsam
Mar 22 2017 02:24
@MathematicsCoding wrong
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:25
Come on...
Keon Samuel
@keonsam
Mar 22 2017 02:25
gear is undefined
Stephen James
@sjames1958gm
Mar 22 2017 02:25
@MathematicsCoding look at getSpeed and then look at your getGear
Victoria Zambrano
@vzambrano98
Mar 22 2017 02:25
@AllanPooley sorry, if i jumped in the middle of that, didn't mean to interrupt. just a noob shouting out stuff lol.
Keon Samuel
@keonsam
Mar 22 2017 02:25
unthing
nothing
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:26

var Bike = function() {
var myBike;
  // Only change code below this line.
  this.getGear = function(change) {
    myBike += change;
    return myBike;
  };
  this.setGear = function(change) {
    myBike += change;
    return myBike;
  };
};
÷÷÷÷
Allan Pooley
@AllanPooley
Mar 22 2017 02:26
@vzambrano98 No it's all good! You're not a noob, you smoked me in finding what was wrong ;)
KatSaldivar
@KatSaldivar
Mar 22 2017 02:26
@AllanPooley which HTML classes are missing quotations? I thought I had all of them
Keon Samuel
@keonsam
Mar 22 2017 02:26
you need a var called geat
gear
lol
var gear;
or var gear = 0;
Allan Pooley
@AllanPooley
Mar 22 2017 02:27

@KatSaldivar Just these ones:

<div class=box>
<h1>Your Local Weather</h1>

<h1 class=city></h1>
<p class=type></p>
<h2 class=temperature></h2>

Alex G
@glazey132
Mar 22 2017 02:27
@sjames1958gm oh... right. that makese sense
KatSaldivar
@KatSaldivar
Mar 22 2017 02:27
oooooooh.... I see! I was just looking at the javascript section. Thanks! @AllanPooley
CamperBot
@camperbot
Mar 22 2017 02:27
katsaldivar sends brownie points to @allanpooley :sparkles: :thumbsup: :sparkles:
:warning: katsaldivar already gave allanpooley points
Alex G
@glazey132
Mar 22 2017 02:27
makes
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:28
var Bike = function() {
var gear = 0;
  // Only change code below this line.

  this.setGear = function(change) {
    gear += change;
  };
  this.getGear = function() {
    return gear;
  };
};
Alex G
@glazey132
Mar 22 2017 02:28
@sjames1958gm so does this make sense?:

var codedChars = [];
var output = str.split('');

//iterate through the array of chars and change them to charCode
for (var j = 0; j < output.length; j++){
codedChars.push(output[j].charCodeAt(0));
}

Stephen James
@sjames1958gm
Mar 22 2017 02:28
@MathematicsCoding Close - now just gear = change not add
Victoria Zambrano
@vzambrano98
Mar 22 2017 02:28
Hey so, if anyone has a sec to look at my for loop in my JS....I can only get it to return one set of data when I need it to return 9 or 10. any help is super duper appreciated
http://codepen.io/vzambrano98/pen/dvZweZ?editors=0010
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:29
@sjames1958gm Done
Stephen James
@sjames1958gm
Mar 22 2017 02:30
@glazey132 Yes , now you have an array of character codes
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:30
What now?
I dont understand how it return 4?
Alex G
@glazey132
Mar 22 2017 02:30
@sjames1958gm thanks for all your help my dude
CamperBot
@camperbot
Mar 22 2017 02:30
glazey132 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 6281 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Mar 22 2017 02:30
@MathematicsCoding getGear returns 4 after setGear(4) -
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:32
I dont know how...
Stephen James
@sjames1958gm
Mar 22 2017 02:33
@MathematicsCoding When setGear(4) is called gear is set to 4 and then getGear is called and returns the gear value which is now 4
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:33
Oh I get the problem
I couldnt pass just because I removed this...
var myCar = new Car();

var myBike = new Bike();
I passed.. just like that
I will just go to pythontutor to understand this code
Keon Samuel
@keonsam
Mar 22 2017 02:36
no way
lol with that code?
yh the code ok
did see that last one
didn't
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:38
Yeah
Thought I didnt need it...
Caijialinxx
@Caijialinxx
Mar 22 2017 02:39
Everybody here speaks en?
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:39
english?
Caijialinxx
@Caijialinxx
Mar 22 2017 02:39
yep
Keon Samuel
@keonsam
Mar 22 2017 02:39
no english
oh
no english
Caijialinxx
@Caijialinxx
Mar 22 2017 02:40
can anyone speak chinese ...
Keon Samuel
@keonsam
Mar 22 2017 02:40
yes chinese
yes chinese
Coy Sanders
@coymeetsworld
Mar 22 2017 02:40
I could I guess if I learned
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:40
不是不是我
Keon Samuel
@keonsam
Mar 22 2017 02:40
but my keyboard english
so you will see english words
Caijialinxx
@Caijialinxx
Mar 22 2017 02:41
怎么截图我的代码给你们看呀 我有问题不知道怎么问
Keon Samuel
@keonsam
Mar 22 2017 02:41
This is Hi in chinese. Hi
Caijialinxx
@Caijialinxx
Mar 22 2017 02:41

function lookUp(firstName, prop){
var i=0;
while(i<contacts.length){
if(contacts[i].firstName==firstName){
if(contacts[i].prop!=='')
return contacts[i].prop;
else return "No such property";
}
i++;
}
return "No such contact";
}

lookUp("Kristian", "lastName");

Saboor Malik
@MathematicsCoding
Mar 22 2017 02:41
Lol抱歉我实际上不会说中文我用英文到中文翻译
Caijialinxx
@Caijialinxx
Mar 22 2017 02:41
OK...
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:42
Anyway
Like this
'''
code
'''
CamperBot
@camperbot
Mar 22 2017 02:42
:bulb: to format code use backticks! ``` more info
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:42
Use ``` instead
Caijialinxx
@Caijialinxx
Mar 22 2017 02:42
This is my code:

```function lookUp(firstName, prop){
var i=0;
while(i<contacts.length){
if(contacts[i].firstName==firstName){
if(contacts[i].prop!=='')
return contacts[i].prop;
else return "No such property";
}
i++;
}
return "No such contact";
}

lookUp("Kristian", "lastName");```

Saboor Malik
@MathematicsCoding
Mar 22 2017 02:43

'''
code
'''

not

'''code
'''

CamperBot
@camperbot
Mar 22 2017 02:43
:bulb: to format code use backticks! ``` more info
Usman Akram
@usmanakram1996
Mar 22 2017 02:43
i need help on this challenge
plz
?
anybody there
Caijialinxx
@Caijialinxx
Mar 22 2017 02:43
I dont know where is the bug
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:43
Type press enter paste code then press enter then type
@Caijialinxx
Hello
@Caijialinxx quote that message
Caijialinxx
@Caijialinxx
Mar 22 2017 02:44

function lookUp(firstName, prop){
var i=0;
while(i<contacts.length){
if(contacts[i].firstName==firstName){
if(contacts[i].prop!=='')
return contacts[i].prop;
else return "No such property";
}
i++;
}
return "No such contact";
}

lookUp("Kristian", "lastName");

......Sorry... I dont know how to do it
Usman Akram
@usmanakram1996
Mar 22 2017 02:45
?? anybody there?
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:46
@Caijialinxx move your mouse over to top right of your message You see three tiny boxs?
Like a list of Reply, quote, edit, or delete
Caijialinxx
@Caijialinxx
Mar 22 2017 02:47
I see that .. then what i should do?
Caijialinxx
@Caijialinxx
Mar 22 2017 02:50
function lookUp(firstName, prop){
  var i=0;
  while(i<contacts.length){
    if(contacts[i].firstName==firstName){
      if(contacts[i].prop!=='')
        return contacts[i].prop;
      else return "No such property";
    }
    i++;
  }
  return "No such contact";
}

lookUp("Kristian", "lastName");
the parameters function lookUp() exists, but it can't run a result and didn't tell me the bug.. @MathematicsCoding Could you help me please?
Victoria Zambrano
@vzambrano98
Mar 22 2017 02:50
If anyone has a sec i could really use some help with what is going wrong with my for loop. I just need a hint.....not even a full on answer
Usman Akram
@usmanakram1996
Mar 22 2017 02:50
hello ... :(
plz tell me
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:51
I see that .. then what i should do?
Timmy56
@Timmy56
Mar 22 2017 02:51
function pairElement(str) {
  //define a map object with all pair possibilities 
  var map = {T:'A', A:'T', G:'C', C:'G'};
  //split str into a char Array
  strArr = str.split('');
  //replace each Array item with a 2d Array using map
  for (var i=0;i<strArr.length;i++){
    strArr[i]=[strArr[i], map[strArr[i]]];
  }
 return strArr;
}

// test here
pairElement("GCG");
@usmanakram1996
Saboor Malik
@MathematicsCoding
Mar 22 2017 02:51
Click quote on this message
I see that .. then what i should do?
Ken Haduch
@khaduch
Mar 22 2017 02:52
@vzambrano98 - I'll have a look.
Usman Akram
@usmanakram1996
Mar 22 2017 02:54
@Timmy56 thanks a lot
CamperBot
@camperbot
Mar 22 2017 02:54
usmanakram1996 sends brownie points to @timmy56 :sparkles: :thumbsup: :sparkles:
:warning: @timmy56's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
Caijialinxx
@Caijialinxx
Mar 22 2017 02:54
function lookUp(firstName, prop){
  var i=0;
  while(i<contacts.length){
    if(contacts[i].firstName==firstName){
      if(contacts[i].prop!=='')
        return contacts[i].prop;
      else return "No such property";
    }
    i++;
  }
  return "No such contact";
}

lookUp("Kristian", "lastName");
the parameters function lookUp() exists, but it can't run a result and didn't tell me the bug.. @MathematicsCoding Could you help me please?
Vikram
@vikramnr
Mar 22 2017 02:55
for(var i=0; i<arr.length; i++)
for(var j=0; j<arr[i].length; j++)
{
product=productarr[i]arr[j];
}
What am i missing here..? any would be suffice
Caijialinxx
@Caijialinxx
Mar 22 2017 02:57
@vikramnr maybe ... it should be arr[i][j]
I guess..
Rudy Hernandez
@rudolphh
Mar 22 2017 03:01
@Caijialinxx use bracket notation instead of dot to check for the prop because it's a string
Vikram
@vikramnr
Mar 22 2017 03:02
@Caijialinxx yeah good point thanks
CamperBot
@camperbot
Mar 22 2017 03:02
vikramnr sends brownie points to @caijialinxx :sparkles: :thumbsup: :sparkles:
:cookie: 21 | @caijialinxx |http://www.freecodecamp.com/caijialinxx
Ken Haduch
@khaduch
Mar 22 2017 03:02
@vzambrano98 - you have an error in your loop - you need to use the length of data[1] to control your loop, and extract the data from data[1], data[2], and data[3]
David Amanze
@GodKingShogun
Mar 22 2017 03:02
hello everyone :smile:
anyone know of a way i can check for undefined, null, 0, false and empty string at the same time without having to write || in between each one
i looked it up on google but couldn't get a clear answer
Ken Haduch
@khaduch
Mar 22 2017 03:04
@vzambrano98 - I think that you were just going out of bounds when you were accessing the data with data[i+3], for example, although I'm surprised that it wasn't dumping some kind of error to the console?
David Amanze
@GodKingShogun
Mar 22 2017 03:06
was i ignored :cry:
Caijialinxx
@Caijialinxx
Mar 22 2017 03:06
@rudolphh Thank you!!!!!!!!!
CamperBot
@camperbot
Mar 22 2017 03:06
caijialinxx sends brownie points to @rudolphh :sparkles: :thumbsup: :sparkles:
:warning: The user instance is not valid. Details: username User already exists (value: "rudolphh"); username is not unique (value: "rudolphh").
Ken Haduch
@khaduch
Mar 22 2017 03:06
@GodKingShogun - are you doing the Falsy Bouncer exercise?
Keon Samuel
@keonsam
Mar 22 2017 03:06
singleVal = array.reduce(function(previousVal, currentVal) {
return previousVal + currentVal;
}, 0);
what is the purpose of the zero
0);
David Amanze
@GodKingShogun
Mar 22 2017 03:07
@khaduch no i am doing the everthing be true challenge
@keonsam it indicates the starting value
Ken Haduch
@khaduch
Mar 22 2017 03:07
@vzambrano98 - I see that I didn't have the JS error reporting turned on in the console, so when I did, it showed an error like so: TypeError: data[(i + 3)] is undefined
David Amanze
@GodKingShogun
Mar 22 2017 03:08
@keonsam so if five was there it would add 5 to your first two elements and continue
@keonsam hopefully that makes sense
:smile:
@khaduch do you have any tips
Ken Haduch
@khaduch
Mar 22 2017 03:09
Keon Samuel
@keonsam
Mar 22 2017 03:10
@GodKingShogun thanks
CamperBot
@camperbot
Mar 22 2017 03:10
keonsam sends brownie points to @godkingshogun :sparkles: :thumbsup: :sparkles:
:cookie: 159 | @godkingshogun |http://www.freecodecamp.com/godkingshogun
David Amanze
@GodKingShogun
Mar 22 2017 03:11
@keonsam :+1:
@khaduch okay let me take a look
@khaduch okay i just looked it so i would just write
````
c0d0er
@c0d0er
Mar 22 2017 03:16
does anybody know why there is error in the console? any idea for fixing? Error: <rect> attribute height: A negative value is not valid. ("-1.9165386110767189"), http://codepen.io/c0d0er/pen/qrjwGg?editors=0010
David Rowan III
@rowanD72
Mar 22 2017 03:16
hello everyone
Ken
@CodeLearnerKen
Mar 22 2017 03:17
Hey guys, I had a question on the Golf problem with Javascript. I completed it but was wondering why its necessary to use the == operator instead of just = for the if/then statements.
Manish Giri
@Manish-Giri
Mar 22 2017 03:17
@CodeLearnerKen =is assigning one value to a variable..
== compares two values/variables.
Ken
@CodeLearnerKen
Mar 22 2017 03:18
Ohh! thank you!
David Amanze
@GodKingShogun
Mar 22 2017 03:18
if (new  Boolean(collection[i]===false)
David Rowan III
@rowanD72
Mar 22 2017 03:18
I need some help on the javascript Profile Lookup. The last two challenges didn't go through.
Usman Akram
@usmanakram1996
Mar 22 2017 03:18
@rowanD72 welcome
David Amanze
@GodKingShogun
Mar 22 2017 03:18
@Manish-Giri :wave:
David Rowan III
@rowanD72
Mar 22 2017 03:18
Thanks @usmanakram1996
CamperBot
@camperbot
Mar 22 2017 03:18
rowand72 sends brownie points to @usmanakram1996 :sparkles: :thumbsup: :sparkles:
:cookie: 267 | @usmanakram1996 |http://www.freecodecamp.com/usmanakram1996
David Amanze
@GodKingShogun
Mar 22 2017 03:18
@khaduch are you still there
Ken
@CodeLearnerKen
Mar 22 2017 03:19
thanks so much @Manish-Giri .. was thinking about it for like 20 minutes!
CamperBot
@camperbot
Mar 22 2017 03:19
codelearnerken sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 4866 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Mar 22 2017 03:19
@GodKingShogun :wave:
Ken Haduch
@khaduch
Mar 22 2017 03:19
@GodKingShogun - yes, just barely here... about to go to sleep. what's up?
Manish Giri
@Manish-Giri
Mar 22 2017 03:19
@CodeLearnerKen :+1:
Ken Haduch
@khaduch
Mar 22 2017 03:19
@rowanD72 - want to post your code?
David Amanze
@GodKingShogun
Mar 22 2017 03:19
@khaduch is this how i would write it to check
Saboor Malik
@MathematicsCoding
Mar 22 2017 03:19
@Manish-Giri can you give me an example of .sort?
David Amanze
@GodKingShogun
Mar 22 2017 03:19
if (new  Boolean(collection[i]===false)
jacob
@bjh2012
Mar 22 2017 03:19
could someone explain this statement to me, "Remember that Arrays have zero-based numbering, which means the last index of the array is length - 1. Our condition for this loop is i < arr.length, which stops when i is at length - 1." At what point does the loop reach -1?
David Amanze
@GodKingShogun
Mar 22 2017 03:20
collection is an object nested in an array
Manish Giri
@Manish-Giri
Mar 22 2017 03:20
@MathematicsCoding
var fruit = ['cherries', 'apples', 'bananas'];
fruit.sort(); // ['apples', 'bananas', 'cherries']
Ken Haduch
@khaduch
Mar 22 2017 03:20
@GodKingShogun - no, they have a recommendation in the document about that. Look for the text: Do not use a Boolean object to convert a non-boolean value to a boolean value. Instead, use Boolean as a function to perform this task:
Saboor Malik
@MathematicsCoding
Mar 22 2017 03:20
@Manish-Giri Well the number...
I dont know how to sort the array from largest to smallest
Manish Giri
@Manish-Giri
Mar 22 2017 03:21
var numbers = [4, 2, 5, 1, 3];
numbers.sort(function(a, b) {
  return a - b;
});
console.log(numbers);

// [1, 2, 3, 4, 5]
David Amanze
@GodKingShogun
Mar 22 2017 03:21
@khaduch that part was confusing but let me take another look
Joseph
@revisualize
Mar 22 2017 03:21
Hey Hey.
Ken Haduch
@khaduch
Mar 22 2017 03:22
@bjh2012 - the loop does not reach -1 - but it should reach length - 1, in other words, the length of the array is arr.length and the last index in the array is arr.length - 1 because the index starts at 0.
@GodKingShogun - just do not use the keyword new...
David Amanze
@GodKingShogun
Mar 22 2017 03:23
@khaduch okay
jacob
@bjh2012
Mar 22 2017 03:23
@khaduch So, arr.length-1 is the false statement needed to stop the loop?
Ken Haduch
@khaduch
Mar 22 2017 03:25
@GodKingShogun - and your code here was a little bit incorrect - it should be if ( Boolean(collection[i])===false)
:point_up: March 21, 2017 11:19 PM
David Rowan III
@rowanD72
Mar 22 2017 03:25
I'm trying to post my code, but I seem to not know how.
Ken Haduch
@khaduch
Mar 22 2017 03:25

@bjh2012 - typically, if you have this code:

var arr = ['one', 'two', 'three', 'four'];`

You have an array with a length of four. But the array index values that you can use are 0, 1, 2, and 3. So you want to make sure that you stop accessing the array after you have used the last value, or in this case, the value 3. So you typically write the for loop to examine this as

for ( var i = 0; i < arr.length; i++ ) {  // your code here }

So it starts at 0, then goes to 1, then goes to 2, then goes to 3. At that point, you can go no farther. But the way that the test condition and the loop works, you then increment i to 4, and then the loop test condition is testing 4 < arr.length, which is 4 < 4, which is false, so the loop ends.

KiingRex
@KiingRex
Mar 22 2017 03:25
hello quick question, can somebody explain how to build word blanks?
Manish Giri
@Manish-Giri
Mar 22 2017 03:26
@KiingRex you need to form a string, and assign it to result, using string concatenation (+). The string has to be formed by concatenating the four parameters in your function - myNoun, myAdjective, etc, along with spaces and (optionally) some words of your own - to form a coherent sentence.
David Amanze
@GodKingShogun
Mar 22 2017 03:27
else if (collection.hasOwnProperty(pre)&& Boolean(collection[pre])===false)
@khaduch ^ it checks to see if it has the key and checks to see if the value is null undefined 0 empty string
is that right
KiingRex
@KiingRex
Mar 22 2017 03:30
hmmm
Alan M.
@Am3ra
Mar 22 2017 03:30
@GodKingShogun Looks alright, does it work though?
jacob
@bjh2012
Mar 22 2017 03:31
@khaduch I see. thank you for the explanation.
CamperBot
@camperbot
Mar 22 2017 03:31
:star2: 2667 | @khaduch |http://www.freecodecamp.com/khaduch
bjh2012 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
Ken Haduch
@khaduch
Mar 22 2017 03:31
@GodKingShogun - that's in the ballpark. It depends on what action you're trying to take. You want to notice if the object does not have the property, or if the property value is false, or maybe if the object has the property and the property is not false - but you're on the right track.
Usman Akram
@usmanakram1996
Mar 22 2017 03:32
for ( var i = 0; i < arr.length; i++ ) { // your code here }
@rowanD72 just copy paste ur code in the chatbox
Craig
@craigabowers2
Mar 22 2017 03:32
Hello, I am in JS and doing "Understanding String Immutability" The instructions for it state "Correct the assignment to myStr to achieve the desired effect."
uhhh.... what does that mean?

// Setup
var myStr = "Jello World";

// Only change code below this line

myStr[0] = "H"; // Fix Me

David Rowan III
@rowanD72
Mar 22 2017 03:33
@usmanakram1996 ok I thought it was another way to post it besides cntl v
Craig
@craigabowers2
Mar 22 2017 03:33
I've changed the "H" to "J" and nothing happened. I added another myStr = "Hello World"; and nothing happened.
My guess is that it has no desired effect?
Coy Sanders
@coymeetsworld
Mar 22 2017 03:34
you can't change a single letter like that @craigabowers2, thats what it means when they say Strings are immutable
you need to reassign the myStr variable to a whole new string, cant just change part of it
David Rowan III
@rowanD72
Mar 22 2017 03:35
I thought it would show up different.
I can't get it to evaluate the last two statements
KiingRex
@KiingRex
Mar 22 2017 03:37
@Manish-Giri sorry i'm just not sure how to form the correct string
Avery Biskup
@fraknard
Mar 22 2017 03:40
For the challenge "Sum All Numbers in a Range" do I have to use the suggestion link's method? Or can I figure it out by myself? In other words, do they want us to practice these new functions within Math?
Craig
@craigabowers2
Mar 22 2017 03:40
@coymeetsworld Thanks, but I don't know what their intentions are. I mean, I just tried this to no avail:
myStr = "Hello World";
myStr[0] = "Hello World";
As well as this to no avail:
myStr = "Hello World";
myStr[0] = "H";
So, I don't get what they mean by setting up a new string for a prior variable?
CamperBot
@camperbot
Mar 22 2017 03:40
craigabowers2 sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 2320 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Avery Biskup
@fraknard
Mar 22 2017 03:42
@craigabowers2 myStr[0] = "Hello World"; = index 0 of myStr is equal to "Hello World".
You are changing the index 0 of that string
Coy Sanders
@coymeetsworld
Mar 22 2017 03:42
you can't reassign part of the string
it has to be the whole string
Manish Giri
@Manish-Giri
Mar 22 2017 03:42
@KiingRex here's an example - var words = "Hello " + "world.";
David Rowan III
@rowanD72
Mar 22 2017 03:42

function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {
if (contacts[i].firstName === firstName) {
if (contacts[i].hasOwnProperty(prop)){
return contacts[i][prop];
}else {
return "No such contact";
}
}
}
return "No such property";
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");

can anyone tell me what I'm doing wrong? I'd greatly appreciate it.
Tiffany
@tiffanymakes
Mar 22 2017 03:51
@rowanD72 try re-reading all of the instructions again. For example, the first part of the instructions state: The function should check if firstName is an actual contact's firstName AND the given property (prop) is a property of that contact. If both are true, then return the "value" of that property. So combine your first two if statements.
David Rowan III
@rowanD72
Mar 22 2017 03:52
@tiffanymakes I have them nested already. So you
@tiffanymakes So you're saying separate them?
Tiffany
@tiffanymakes
Mar 22 2017 03:53
Combine
David Rowan III
@rowanD72
Mar 22 2017 03:54
ok @tiffanymakes
Joseph
@revisualize
Mar 22 2017 03:55
@rowanD72 You need to switch.
@rowanD72 You need to switch your return for no such property with your return for no such contact and it should work.
Saboor Malik
@MathematicsCoding
Mar 22 2017 03:56
Oh my god This challenge...
Joseph
@revisualize
Mar 22 2017 03:56
@MathematicsCoding What?
Saboor Malik
@MathematicsCoding
Mar 22 2017 03:56
Basic Algorithm Scripting....
Joseph
@revisualize
Mar 22 2017 03:56
Which?
Saboor Malik
@MathematicsCoding
Mar 22 2017 03:57
var reverseString =("hello", "Howdy", "Greeting from Earth");
reverseString.reverse();
Reverse a String
Forgot to add console.log
Joseph
@revisualize
Mar 22 2017 03:57
@MathematicsCoding Okay. Look.
@MathematicsCoding You can't reverse a string.
Saboor Malik
@MathematicsCoding
Mar 22 2017 03:58
oh...
Do I have to change them into array?
Joseph
@revisualize
Mar 22 2017 03:58
@MathematicsCoding You can reverse an array.
Saboor Malik
@MathematicsCoding
Mar 22 2017 03:58
Without quotes?
Joseph
@revisualize
Mar 22 2017 03:58
@MathematicsCoding In JavaScript what are values without quotes?
Saboor Malik
@MathematicsCoding
Mar 22 2017 04:00
string?
Joseph
@revisualize
Mar 22 2017 04:00
In JavaScript if a value doesn't have quotes around it ... It is either a keyword, variable or a number or .. There's a few other things.
@MathematicsCoding No.
@MathematicsCoding Quotes define strings. Having quotes around something is what makes it a string.
Saboor Malik
@MathematicsCoding
Mar 22 2017 04:00
Can it be letter
var reverseString =[hello, Howdy, Greeting from Earth]; 
reverseString.reverse();
console.log(reverseString);
Joseph
@revisualize
Mar 22 2017 04:01
@MathematicsCoding It can't be a letter if it doesn't have quotes around it.
Saboor Malik
@MathematicsCoding
Mar 22 2017 04:01
oh..
Joseph
@revisualize
Mar 22 2017 04:01
@MathematicsCoding Are hello, Howdy .... variables?
Saboor Malik
@MathematicsCoding
Mar 22 2017 04:01
no
Joseph
@revisualize
Mar 22 2017 04:01
OH!
Hmmm
Saboor Malik
@MathematicsCoding
Mar 22 2017 04:01

_
_-
Vikram
@vikramnr
Mar 22 2017 04:02

function lookUpProfile(firstName, prop){
// Only change code below this line
var answer;

if(firstName===contacts.firstName){
if(prop=="lastName"||prop=="number"||prop=="likes"){

  answer=contacts[prop];
}
else{
  answer="Not such property";
}

}
else{
answer="No such contact";
}
return answer;
// Only change code above this line
} What i'm missing in this function.. any clue would be good.

Saboor Malik
@MathematicsCoding
Mar 22 2017 04:02
@vikramnr Not
Joseph
@revisualize
Mar 22 2017 04:02
@vikramnr contacts is an Array of Objects.
David Rowan III
@rowanD72
Mar 22 2017 04:06
@tiffanymakes explain what you mean by combine the if statements? I have them nested and the code still won't work. I even had them as stand alone if statements and still nothing . So please explain what you mean by "combine them."
Saboor Malik
@MathematicsCoding
Mar 22 2017 04:08
Ugh I will do this tomorrow
Good Night
David Rowan III
@rowanD72
Mar 22 2017 04:09
@revisualize ok let me see thanks
CamperBot
@camperbot
Mar 22 2017 04:09
rowand72 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3568 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Mar 22 2017 04:12
@rowanD72 It should be just switching two return statements and you should be done.
David Rowan III
@rowanD72
Mar 22 2017 04:13
@revisualize THANKS!!!! That was the problem
CamperBot
@camperbot
Mar 22 2017 04:13
rowand72 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: rowand72 already gave revisualize points
Joseph
@revisualize
Mar 22 2017 04:13
@rowanD72 :+1:
Sadik Ekin Özbay
@sadikekin
Mar 22 2017 04:18
guys do you have idea of why this code is not working var myStr = "I am a \"double quoted\" string inside \"double quotes\" . This question is related with Escaping Literal Quotes in Strings
Joseph
@revisualize
Mar 22 2017 04:19
@sadikekin You're not ending terminating your quote instantiation.
Sadik Ekin Özbay
@sadikekin
Mar 22 2017 04:21
@revisualize i wrote it wrong var myStr = "I am a \"double quoted\" string inside \"double quotes\""
still not working btw
Joseph
@revisualize
Mar 22 2017 04:23
@sadikekin Well. with that you're missing a .
Sadik Ekin Özbay
@sadikekin
Mar 22 2017 04:24
finally, my bad. thanks @revisualize
CamperBot
@camperbot
Mar 22 2017 04:24
sadikekin sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3569 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Mar 22 2017 04:24
:dancers:
@sadikekin With freeCodeCamp your strings need to be exact.
KiingRex
@KiingRex
Mar 22 2017 04:25
hello can somebody help me with this question
Create a function called functionWithArgs that accepts two arguments and outputs their sum to the dev console.
Joseph
@revisualize
Mar 22 2017 04:25
@KiingRex What code have you written?
KiingRex
@KiingRex
Mar 22 2017 04:26
function functionWithArgs(){
console.log(7+9);
}
functionWithArgs(3, 16);
i put the last line because it says to call the function after
KiingRex
@KiingRex
Mar 22 2017 04:33
and for the function part you can't put numbers in it so i wasn't sure what to do
Tiffany
@tiffanymakes
Mar 22 2017 04:33
@KiingRex you want to be able to re-use your functions. With what you have, it will always print 7+9 to the console.
Try following the example, just with addition rather than subtraction.
Jorge Castaño Delgado
@jhcastanod
Mar 22 2017 04:35
hey guys. one question... why this code is returning the length of the array instead the arrayitself?
function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  var box = arguments[0].push(num);

  console.log(box);
}
jacob
@bjh2012
Mar 22 2017 04:36
for (var i=0; i<arr.length; i++){
for (var j=0; j<arr[i].length; j++){
product*=arr[i][j];
}}
So, the first loop goes to each array, and the second loop goes to each number within the array, and product*=arr[i][j]; basically just multiplies every number in each array. Am I getting that right?
NaveenRathor
@NaveenRathor
Mar 22 2017 04:37

// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

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

 );

}
// Test your code by modifying these values
checkObj("gift");

any suggestion
Tiffany
@tiffanymakes
Mar 22 2017 04:39
@jhcastanod The push() method adds one or more elements to the end of an array and returns the new length of the array. Just return arguments[0] after you push() num.
m-madden
@m-madden
Mar 22 2017 04:39

Having trouble with the following ...

```function mutation(arr) {

var lowerArray = [];

for (i=0; i<arr.length; i++) {

lowerArray.push(arr[i].toLowerCase());    

}

var smallArray = lowerArray1;

for (i=0; i<smallArray.length; i++) {

return lowerArray[0].indexOf(smallArray[i]) !== -1;

}

}

mutation(["hello", "hey"]);
```

Passes every test except the one supplied in the code...

ashesashes
@ashesashes
Mar 22 2017 04:39
Hi there. Trying to solve Profile Lookup but keep running into an issue where all my tests but one pass.
function lookUpProfile(firstName, prop){
// Only change code below this line

  for (var i = 0; i < contacts.length; i ++) {

    while (contacts[i].firstName === firstName) {
      if (contacts[i].hasOwnProperty(prop)) {
        //console.log(contacts[i].firstName);
        console.log(contacts[i][prop]);
        return contacts[i][prop];
      } else {
        console.log("No such property");
        return "No such property";
      }
    } 
   }

lookUpProfile("Akira", "likes"); // does not pass if I use if..else statements 
lookUpProfile("Sherlock", "likes");
lookUpProfile("Kristian", "lastName");
lookUpProfile("Bob", "number");   // does not pass 
lookUpProfile("Akira", "address");
lookUpProfile("Harry", "likes");
Jorge Castaño Delgado
@jhcastanod
Mar 22 2017 04:40
@tiffanymakes it's werid 'cuz look at this: https://www.w3schools.com/jsref/jsref_push.asp
NaveenRathor
@NaveenRathor
Mar 22 2017 04:41

// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

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

 );

}
// Test your code by modifying these values
checkObj("gift");

KiingRex
@KiingRex
Mar 22 2017 04:41
@tiffanymakes i'm just not sure how to output 2 numbers instead of 1
ashesashes
@ashesashes
Mar 22 2017 04:41
The goal is to loop through an array of objects and check to see if the value of firstName that is passed to the function exists and if so, check to see if the property exists. Else return "Contact not found". I cannot get the last one to work.
Tiffany
@tiffanymakes
Mar 22 2017 04:42
@jhcastanod Under definition: The push() method adds new items to the end of an array, and returns the new length.
m-madden
@m-madden
Mar 22 2017 04:42
function mutation(arr) {

  var lowerArray = [];

  for (i=0; i<arr.length; i++) {

    lowerArray.push(arr[i].toLowerCase());    

  }

  var smallArray = lowerArray[1];


  for (i=0; i<smallArray.length; i++) {

    return lowerArray[0].indexOf(smallArray[i]) !== -1;

  }

}

mutation(["hello", "hey"]);
Tiffany
@tiffanymakes
Mar 22 2017 04:42
@KiingRex function testFun(param1, param2) { console.log(param1, param2); }
@jhcastanod return the array (in your case arguments[0]) after you push() the num. Don't assign it to box and return box. Box is the length because of what the .push() method returns.
Ronald Johnson
@ronnieg1988
Mar 22 2017 04:46

// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
 myObj.hasOwnProperty();
  myObj.hasOwnProperty();
  myObj.hasOwnProperty();
  if (myObj.hasOwnProperty()){
    return myObj[""];
  }
  return "Change Me!";
}

// Test your code by modifying these values
checkObj("gift");
dont think any of this is right
Jorge Castaño Delgado
@jhcastanod
Mar 22 2017 04:46
@tiffanymakes ohh yes, works! thanks girl
CamperBot
@camperbot
Mar 22 2017 04:46
jhcastanod sends brownie points to @tiffanymakes :sparkles: :thumbsup: :sparkles:
:cookie: 318 | @tiffanymakes |http://www.freecodecamp.com/tiffanymakes
Tiffany
@tiffanymakes
Mar 22 2017 04:47
:thumbsup:
Vikram
@vikramnr
Mar 22 2017 04:48
@revisualize I should add an loop right?
ashesashes
@ashesashes
Mar 22 2017 04:50
@ronnieg1988 hasOwnProperty needs to test a property - ex: myObj.hasOwnProperty(checkProp);
if the property exists, you want to return its value - myObj[checkProp];
Magson Martins Magalhaes
@mistermagson
Mar 22 2017 04:56
Palindrome issue: why palindrome("1 eye for of 1 eye.") should return false?
KiingRex
@KiingRex
Mar 22 2017 04:56
@tiffanymakes with the code i put it showed these as mistakes: functionWithArgs(1,2) should output 3
functionWithArgs(7,9) should output 16
drinkwaterman
@drinkwaterman
Mar 22 2017 04:57
@ashesashes it's powerful when used in a loop. somewhere else, it brings only the first index.
Tiffany
@tiffanymakes
Mar 22 2017 04:59
@KiingRex you need to list the parameters for your function. You can name them whatever you want. Like,param1 and param2. Then use them in the function, instead of 7 and 9.
Use the example, except with addition:
function ourFunctionWithArgs(a, b) { console.log(a - b); }
Chris Cullen
@123xylem
Mar 22 2017 04:59

My Mehtod override isnt overriding my POST requests to make the put/delete requests...

Here is the way i depend and use it with some other things i use

var express           = require("express"),
 app              = express(),
 mongoose         =require("mongoose"),
 bodyParser       = require("body-parser"),
 camp             =require("./models/campgrounds"),                            //require campgrounds.js in models dir
 seedDB           =require("./seeds"),                                         //require seeds.js 
 comment           =require("./models/comment"),
 User              =require("./models/user"),
 passport            =require("passport"),
 localStrategy        =require("passport-local"),
 methodOverride      =require("method-override"),
 router                =require("./routes/camproutes")

 var commentRoutes  =require("./routes/comments")
 var campRoutes     =require("./routes/camproutes")
 var authRoutes     =require("./routes/auth")


mongoose.connect("mongodb://localhost/yelpcamp");

app.use(express.static(__dirname+"/public"));
app.use(bodyParser.urlencoded({ extended: true}));

app.set("view engine", "ejs");

//===========================USE the  routes assigned to router instead of app. And Append the shortcuts 
 app.use("/camps/:id/comments",commentRoutes);
 app.use("/",authRoutes);
 app.use("/camps",campRoutes);
//==========================Camp Routes =====================================

 app.use(methodOverride("_method"));

I use router.put not app.put.. but i export router as an express router
Here are my routes that call it..

var express=require("express");
var router=express.Router();
var camp=require("../models/campgrounds")
var comment=require("../models/comment")
var passport=require("passport")
var User= require("../models/user")
var currentUser=require("../app");

var express=require("express");
var router=express.Router();
var camp=require("../models/campgrounds")
var comment=require("../models/comment")
var passport=require("passport")
var User= require("../models/user")
var currentUser=require("../app");

//Post Edit Info
router.put("/:id",function(req,res){ console.log("HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", req.params) 
    camp.findByIdAndUpdate(req.params.id,req.body.camp,function(err,foundCamp){       //find by id. update with camp properties in form submit and then execute func
        if (err){console.log(err)}
        else{  res.redirect("/camps/"+req.params.id)}

    })
});




router.delete("/:id",function(req,res){
   camp.findByIdAndRemove(req.params.id,function(err){
        if (err){console.log(err)}
        else{    res.redirect("/camps")
}
    })
})
module.exports=router;

Lastly Here is the form that uses method overide

  <form method="POST" action="/camps/<%=camp.id%>?_method=PUT" >
        <div>
      <input class="form-control" type="text" value="<%=camp.name%>" name="camp[name]">
       </div><div >
      <input class="form-control" type="text" value="<%=camp.image%>" name="camp[image]">
   </div>  

       <div class="form-group">
      <input class="form-control" type="text" value="<%=camp.description%>" name="camp[description]">
   </div>

      <div class="form-group">  
      <button class="btn btn-lg btn-primary btn-block">Submit</button>
  </div>
    </form>

I am at a total loss as to why method overide isnt working.. One time I changed the method/action order on the form and it worked for a while but then stopped again.. Its really strange..
PLease help!

Magson Martins Magalhaes
@mistermagson
Mar 22 2017 05:01
alt
Vikram
@vikramnr
Mar 22 2017 05:03

var answer;
var i=0;
for(i=0;i<contacts.length;i++)
{
if(firstName===contacts[i].firstName){
if(prop=="lastName"||prop=="number"||prop=="likes"){

  answer=contacts[prop];
}
else{
  answer="Not such property";
}

}
else{
answer="No such contact";
}
}
return answer;
// Only change code above this line
}
Is this right way to access array of objects

ashesashes
@ashesashes
Mar 22 2017 05:05
@drinkwaterman 👍
Magson Martins Magalhaes
@mistermagson
Mar 22 2017 05:07
alt
kailasa8055
@kailasa8055
Mar 22 2017 05:07
@vikramnr HOW DO i do this?
FirstLine
\SecondLine\
ThirdLine
in javascript?
i m new here
pls help
Kevin Collins
@kev0587
Mar 22 2017 05:08

im having difficulty with the Check for Palindromes challenge, so I'm reading docs on how to remove alpha-numeric chars from a string, but all of the examples they give include /gi or /g. can anybody tell me what that means?

name.replace(/[^0-9a-zA-Z]/g, '');

the g that's after Z]/..can't find anywhere that they explain what that actually is

Vikram
@vikramnr
Mar 22 2017 05:09
@kailasa8055 trying using \n \..this will get the desired o\p
Magson Martins Magalhaes
@mistermagson
Mar 22 2017 05:10
@kev0587 g means global.
it will check every match not just the first one
kailasa8055
@kailasa8055
Mar 22 2017 05:10
@vikramnr thanks a lot
CamperBot
@camperbot
Mar 22 2017 05:10
kailasa8055 sends brownie points to @vikramnr :sparkles: :thumbsup: :sparkles:
:cookie: 221 | @vikramnr |http://www.freecodecamp.com/vikramnr
Kevin Collins
@kev0587
Mar 22 2017 05:11
@mistermagson ohhh. got it. and im assuming i means ignore, so it will ignore what you specify?
Magson Martins Magalhaes
@mistermagson
Mar 22 2017 05:12
i is for ignore the capitalized. if you use the 'i' you will get 'A' or 'a'
KiingRex
@KiingRex
Mar 22 2017 05:13
@tiffanymakes i've used it but i just can't get both answers to output at the same time
ashesashes
@ashesashes
Mar 22 2017 05:13
@vikramnr This was the first approach I tried. Nothing passes except for the "no such contact". Not sure why that is
Kevin Collins
@kev0587
Mar 22 2017 05:13
awesome, thanks @mistermagson
CamperBot
@camperbot
Mar 22 2017 05:13
kev0587 sends brownie points to @mistermagson :sparkles: :thumbsup: :sparkles:
Magson Martins Magalhaes
@mistermagson
Mar 22 2017 05:13
to negate what you specify use the ^
CamperBot
@camperbot
Mar 22 2017 05:13
:cookie: 248 | @mistermagson |http://www.freecodecamp.com/mistermagson
Tiffany
@tiffanymakes
Mar 22 2017 05:15
@KiingRex what does your code look like now?
ashesashes
@ashesashes
Mar 22 2017 05:15
@ashesashes @vikramnr - I figured it out. Turns out that I was running the last check inside my while loop.
Vikram
@vikramnr
Mar 22 2017 05:16
@ashesashes could you clue of other approach u have tried..because for me also it is still passing one condition only.. :worried:
ashesashes
@ashesashes
Mar 22 2017 05:18
@vikramnr
 for (var i = 0; i < contacts.length; i ++) {

    while (contacts[i].firstName === firstName) {
      if (contacts[i].hasOwnProperty(prop)) {
        //console.log(contacts[i].firstName);
        console.log(contacts[i][prop]);
        return contacts[i][prop];
      } else {
        console.log("No such property");
        return "No such property";
      }
     } 

   } 


     return "No such contact";

// Only change code above this line
}
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 05:19
@ashesashes why have you used a while loop?
Vikram
@vikramnr
Mar 22 2017 05:19
@ashesashes I could have used built in function
ashesashes
@ashesashes
Mar 22 2017 05:20
@HeebieGeeBee - I should have used an if - since it failed the first time, I used a while loop instead. If statement is the better choice
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 05:20
@ashesashes yeah
Magson Martins Magalhaes
@mistermagson
Mar 22 2017 05:22
@kev0587 /[^0-9a-zA-Z]/g will match for everything which is not a letter or number and for this challenge we just want the letters at first moment.
KiingRex
@KiingRex
Mar 22 2017 05:22

@tiffanymakes
function functionWithArgs(param1, param2){
console.log(1+2 , 7+9);
}

functionWithArgs(3,16);

Vamp
@the-vampiire
Mar 22 2017 05:22
help with card counter section?

var count = 0;

function cc(card) {
  // Only change code below this line
  switch(card){
    case 2:
      count++;
      return count+' Bet';
    case 3:
      count++;
      return count+' Bet';
    case 4:
      count++;
      return count+' Bet';
    case 5:
      count++;
      return count+' Bet';
    case 6:
      count++;
      return count+' Bet';  
    case 7:
      return count+' Hold';
    case 8:
      return count+' Hold';
    case 9:
      return count+' Hold';
    case 10:
      count--;
      return count+' Hold';
    case 'J':
      count--;
      return count+' Hold';
    case 'Q':
      count--;
      return count+' Hold';
    case 'K':
      count--;
      return count+' Hold';
    case 'A':
      count--;
      return count+' Hold';
  }

  // Only change code above this line
}
failing on these two cases:
Cards Sequence 2, J, 9, 2, 7 should return "1 Bet"
Cards Sequence 2, 2, 10 should return "1 Bet"
Magson Martins Magalhaes
@mistermagson
Mar 22 2017 05:23
So, use /[^A-Za-z]/g @kev0587
Vamp
@the-vampiire
Mar 22 2017 05:24
I think it is only showing me output for the first case that fails —> output is '0 Hold'
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 05:24
@mistermagson numbers need to be included for the palindrome challenge
@the-vampiire dont make any returns in the switch statement
@the-vampiire evaluate the count after the switch statement then return the count along with bet or hold depending on what the value of count is
Jor
@joreyesl
Mar 22 2017 05:25
@the-vampiire the switch is only supposed to update count, the return should be done after the switch. You should check if after the switch, count is greater than 0, then should return a bet, otherwise a hold.
Magson Martins Magalhaes
@mistermagson
Mar 22 2017 05:25
@HeebieGeeBee OMG, my mistake! " all non-alphanumeric characters" Thanks
CamperBot
@camperbot
Mar 22 2017 05:25
mistermagson sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1114 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Vamp
@the-vampiire
Mar 22 2017 05:26
@HeebieGeeBee @joreyesl thank you
CamperBot
@camperbot
Mar 22 2017 05:26
the-vampiire sends brownie points to @heebiegeebee and @joreyesl :sparkles: :thumbsup: :sparkles:
:star2: 1115 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
:cookie: 655 | @joreyesl |http://www.freecodecamp.com/joreyesl
Tiffany
@tiffanymakes
Mar 22 2017 05:26
@KiingRex use your parameter names (param1 and param2) instead of the arguments (1 and 2) and (7 and 9) in your function. Just follow the example, except with addition.
function ourFunctionWithArgs(a, b) { console.log(a - b); }
Vamp
@the-vampiire
Mar 22 2017 05:29
this did not fix it

var count = 0;

function cc(card) {
  // Only change code below this line
  switch(card){
    case 2:
      count++;
      break;
    case 3:
      count++;
      break;
    case 4:
      count++;
      break;
    case 5:
      count++;
      break;
    case 6:
      count++;
      break;
    case 7:
      break;
    case 8:
      break;
    case 9:
      break;
    case 10:
      count--;
      break;
    case 'J':
      count--;
      break;
    case 'Q':
      count--;
      break;
    case 'K':
      count--;
      break;
    case 'A':
      count--;
      break;
  }

  if (count > 1){
    return count+' Bet';
  }
  else if (count < 1){
    return count+' Hold';
  }

  // Only change code above this line
}
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 05:30
@the-vampiire what does it return if the count is 1?
Jor
@joreyesl
Mar 22 2017 05:30

@the-vampiire when do we need to bet? when count is > 1 or > 0?

When the count is positive, the player should bet high. When the count is zero or negative, the player should bet low.

KiingRex
@KiingRex
Mar 22 2017 05:30
@tiffanymakes thank you so much :) have a good night!
CamperBot
@camperbot
Mar 22 2017 05:30
kiingrex sends brownie points to @tiffanymakes :sparkles: :thumbsup: :sparkles:
:cookie: 319 | @tiffanymakes |http://www.freecodecamp.com/tiffanymakes
Vamp
@the-vampiire
Mar 22 2017 05:31
@HeebieGeeBee @joreyesl ah yes should be > 0 and just else for the other. thank you
CamperBot
@camperbot
Mar 22 2017 05:31
the-vampiire sends brownie points to @heebiegeebee and @joreyesl :sparkles: :thumbsup: :sparkles:
:warning: the-vampiire already gave joreyesl points
:warning: the-vampiire already gave heebiegeebee points
Tiffany
@tiffanymakes
Mar 22 2017 05:31
@KiingRex no problem, good night!
kailasa8055
@kailasa8055
Mar 22 2017 05:35
Screenshot (3).png
what is wrong in this?
someone pls help i'm struck
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 05:36
need to use a backslash to escape the backslash
thats meant to be part of the string
Jor
@joreyesl
Mar 22 2017 05:37
@kailasa8055 how are you supposed to escape a backslash? is just \?
Magson Martins Magalhaes
@mistermagson
Mar 22 2017 05:37
@joreyesl thats right!
@joreyesl ...\n\ \Secon...
without spaces
Jor
@joreyesl
Mar 22 2017 05:39
@kailasa8055 look at the chart that they give you. what is the code for backslash?
@mistermagson :thumbsup:
kailasa8055
@kailasa8055
Mar 22 2017 05:40
@joreyesl yeah i got it thanks a lot :)
CamperBot
@camperbot
Mar 22 2017 05:40
kailasa8055 sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 656 | @joreyesl |http://www.freecodecamp.com/joreyesl
kailasa8055
@kailasa8055
Mar 22 2017 05:41
what are these brownie points what can we do with them i'm new here @camperbot
Jor
@joreyesl
Mar 22 2017 05:43
@kailasa8055 they aren't really used for anything, just a way to show appreciation I suppose
kailasa8055
@kailasa8055
Mar 22 2017 05:44
@joreyesl thanks!
CamperBot
@camperbot
Mar 22 2017 05:44
kailasa8055 sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:warning: kailasa8055 already gave joreyesl points
Magson Martins Magalhaes
@mistermagson
Mar 22 2017 05:47
kinda score
Chris Cullen
@123xylem
Mar 22 2017 05:47

Any Idea why my method override isnt working?

    <form  action="/camps/<%=camp.id%>?_method=PUT" method="POST" >//My form

//====Method override 
 methodOverride      =require("method-override"),
 app.use(methodOverride("_method"));

//=====My Routes
router.put("/:id",function(req,res){ console.log("HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", req.params) 
    camp.findByIdAndUpdate(req.params.id,req.body.camp,function(err,foundCamp){       //find by id. update with camp properties in form submit and then execute func
        if (err){console.log(err)}
        else{  res.redirect("/camps/"+req.params.id)}

    })
});

One time this worked by changing the order of method/action in my form but no more... Any ideas?

Vamp
@the-vampiire
Mar 22 2017 05:48

Section: Using objects for lookups

Wondering why
results = lookup.val
does not give same result as
results = lookup[val]

// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line

  var lookup = {
    'alpha':'Adams',
    'bravo':'Boston',
    'charlie':'Chicago',
    'delta':'Denver',
    'echo':'Easy',
    'foxtrot':'Frank'
  };

  result = lookup[val];
// the following does not work:
// result = lookup.val;


  // Only change code above this line
  return result;
}
Jor
@joreyesl
Mar 22 2017 05:49
@mistermagson ty for the link
CamperBot
@camperbot
Mar 22 2017 05:49
joreyesl sends brownie points to @mistermagson :sparkles: :thumbsup: :sparkles:
:cookie: 250 | @mistermagson |http://www.freecodecamp.com/mistermagson
Vamp
@the-vampiire
Mar 22 2017 05:49
I thought that bracket and dot notation were interchangeable and up to user preference (unless in case of a key with a space in its name)
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 05:50
@the-vampiire parameters and variables can only be used with brackets
Jor
@joreyesl
Mar 22 2017 05:50
@the-vampiire if you are using literal strings, then yes. But if you are using a variable you have to use bracket notation.
Vamp
@the-vampiire
Mar 22 2017 05:51
@joreyesl @HeebieGeeBee thank you for explanation
CamperBot
@camperbot
Mar 22 2017 05:51
the-vampiire sends brownie points to @joreyesl and @heebiegeebee :sparkles: :thumbsup: :sparkles:
:warning: the-vampiire already gave joreyesl points
:warning: the-vampiire already gave heebiegeebee points
Jor
@joreyesl
Mar 22 2017 05:52
@the-vampiire when you do lookup.val, you are saying lookup the key "val" not use the value stored in val, lookup.val is the same as lookup["val"], but what you really want is lookup[val]
Joseph
@revisualize
Mar 22 2017 05:56
Because.
@the-vampiire Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 05:57
@revisualize yo, made any videos yet?
Joseph
@revisualize
Mar 22 2017 05:58
No. :(
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 05:58
oh ok
devpaaji
@devpaaji
Mar 22 2017 05:59
@revisualize
var my_value = null;
 console.log(typeof my_value); // object

if (my_value && typeof my_value === 'object') {    
         console.log("True");
 } else{
    console.log("False");
 }
I see false getting logged
@HeebieGeeBee
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 06:01
well my_value is falsy
Vamp
@the-vampiire
Mar 22 2017 06:01
@devpaaji didn’t you set my_value = null? so my_value != ‘object’
typeof my_value === ‘object’ but you have && operator so it will go to else
devpaaji
@devpaaji
Mar 22 2017 06:01
is it because null is falsy and all objects are truthy
Jor
@joreyesl
Mar 22 2017 06:01
@devpaaji typeof null === 'object' its a known issue that will likely never get fixed. http://2ality.com/2013/10/typeof-null.html
devpaaji
@devpaaji
Mar 22 2017 06:02
@the-vampiire typeof is object
Joseph
@revisualize
Mar 22 2017 06:02
@devpaaji null is a falsey value.
devpaaji
@devpaaji
Mar 22 2017 06:02
console.log(typeof my_value); // object
Vamp
@the-vampiire
Mar 22 2017 06:02
yes that part is true but my_value != ‘object’ and since you have && operator and one operand is false then the whole condition is false
Joseph
@revisualize
Mar 22 2017 06:02
But, NULL is still a VALSE value.
@devpaaji if (my_value && That is FALSE
So the && part doesn't matter.
var my_value = null;
 console.log(typeof my_value); // object

if (!my_value && typeof my_value === 'object') {    
         console.log("True");
 } else{
    console.log("False");
 }
This will output TRUE
Jor
@joreyesl
Mar 22 2017 06:03
@devpaaji typeof is an operator, it returns a string, for null it returns 'object' that does not mean that null itself is an object.
Joseph
@revisualize
Mar 22 2017 06:04
@joreyesl That isn't the issue.
Look.
the value of my_value is null
Jor
@joreyesl
Mar 22 2017 06:04
@revisualize ik
Joseph
@revisualize
Mar 22 2017 06:04
if (null && typeof .....)
null still evaluates to a FALSY value.
So, they both will never be true.
devpaaji
@devpaaji
Mar 22 2017 06:05
if (my_value && typeof my_value === 'object') {    
         console.log("True");
 } else{
    console.log("False");
 }
Joseph
@revisualize
Mar 22 2017 06:05
Unless the logic is changed.
devpaaji
@devpaaji
Mar 22 2017 06:05
now @revisualize
Joseph
@revisualize
Mar 22 2017 06:05
@devpaaji What is the value of the variable my_value?
devpaaji
@devpaaji
Mar 22 2017 06:05
null
Joseph
@revisualize
Mar 22 2017 06:05
False
devpaaji
@devpaaji
Mar 22 2017 06:05
correct
Joseph
@revisualize
Mar 22 2017 06:05
What's your issue?
devpaaji
@devpaaji
Mar 22 2017 06:05
typeof my_value === 'object' // true
Joseph
@revisualize
Mar 22 2017 06:06
Correct.
devpaaji
@devpaaji
Mar 22 2017 06:06
false && true // will be false
right
Joseph
@revisualize
Mar 22 2017 06:06
false && true is false..
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 06:06
if(my_value) what do you think this is doing?
devpaaji
@devpaaji
Mar 22 2017 06:06
so false is getting logged
Joseph
@revisualize
Mar 22 2017 06:06
Correct.
@devpaaji What's the problem?
devpaaji
@devpaaji
Mar 22 2017 06:07
now its fixed i was just trying to understand
typeof
var myFunction = new Function("x", "y", "return x * y"); 
console.log( typeof myFunction); // logs Function and not object?
Joseph
@revisualize
Mar 22 2017 06:07
That's a horrible way of trying to understand typeof
John Nunns
@johnnunns
Mar 22 2017 06:08
function Test(numbers){
  // ...
  function isOdd(num) {return num%2===1}

  return Array.from(numbers).reduce((a,b,i)=> isOdd(b)? i: a, [])
}

Test(2,2,3,4)
devpaaji
@devpaaji
Mar 22 2017 06:08
ok
Joseph
@revisualize
Mar 22 2017 06:08
@devpaaji Do you know how you can get the answer to that?
@devpaaji Run it
John Nunns
@johnnunns
Mar 22 2017 06:08
trying to write this a bit fancier, but I'm just returning an empty array
devpaaji
@devpaaji
Mar 22 2017 06:08
@johnnunns which one should i run
kailasa8055
@kailasa8055
Mar 22 2017 06:09
Screenshot (4).png
what to do?
Joseph
@revisualize
Mar 22 2017 06:09
@kailasa8055 You need to escape the backslash and carriage-return in the correct order.
Jor
@joreyesl
Mar 22 2017 06:11
@devpaaji the Function constructor returns a function regardless if its called with new or not. That is why it logs function and not object when you call it with new
devpaaji
@devpaaji
Mar 22 2017 06:11
all types in JS work like objects
@joreyesl
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 06:12
@johnnunns why do you return i? if isOdd(b) is true?
Joseph
@revisualize
Mar 22 2017 06:12
@devpaaji They do?
devpaaji
@devpaaji
Mar 22 2017 06:12
Functions are also objects
then why it logs function
we use a new keyword to create a special function
for producing objects instances
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 06:13
@johnnunns seems to me filter would be a better metho
do you want to filter out all the odd?
devpaaji
@devpaaji
Mar 22 2017 06:13
every function comes with in built this, arguments and its parameters
Joseph
@revisualize
Mar 22 2017 06:13
@devpaaji You know that's a good question for @Masd925
devpaaji
@devpaaji
Mar 22 2017 06:14
special functions behave like this
check thius
John Nunns
@johnnunns
Mar 22 2017 06:14
I was hoping to just return the index of the odd @HeebieGeeBee
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 06:15
@johnnunns so what will the reduce function do with that?
Jor
@joreyesl
Mar 22 2017 06:15
@devpaaji that is true, but the Function constructor behaves differently, it does not return a regular object, it returns a function object
devpaaji
@devpaaji
Mar 22 2017 06:15
function Circle(radius)
{  
  //var this = {}; // JS internally creates this as empty object
// this __proto__ = Circle.prototype // internal link to the parent prototype, which is also an empty object
  this.radius = radius;
  this.getArea = getArea;
  //return this;
}
Joseph
@revisualize
Mar 22 2017 06:15
@devpaaji Or you could ask: @moigithub or @sjames1958gm or @Chrono79 or @saintpeter or @0x0936 or ... @storbeck or .... Actually there's a bunch of other people you could ask that question.
I don't know.
I don't care.
devpaaji
@devpaaji
Mar 22 2017 06:16
so when you create a new instance
var bigCircle = new Circle(100);
those lines are actually written for you by JS
John Nunns
@johnnunns
Mar 22 2017 06:16
I was hoping I could reduce it to a single value, the index. @HeebieGeeBee
but, I could do something with filter, one sec.
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 06:17
@johnnunns the index of what?
Jor
@joreyesl
Mar 22 2017 06:17
@johnnunns you know numbers is only the first argument?
John Nunns
@johnnunns
Mar 22 2017 06:18
of the first number that the reduce function will say is true
Jor
@joreyesl
Mar 22 2017 06:19
@johnnunns ok so you want to get only the odd numbers or even?
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 06:21
think he wants just the index
think a loop would be better for finding an index in an array
but i dunno
John Nunns
@johnnunns
Mar 22 2017 06:22
I think I can do it I just need to reformat the argument actually
the argument is called in as example "1 2 3 4 5"
so i need to get rid of the spaces
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 06:22
why will that matter?
Jor
@joreyesl
Mar 22 2017 06:23
i'm confused :/
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 06:23
@johnnunns reduce is going to act upon the array
John Nunns
@johnnunns
Mar 22 2017 06:23
when I use Array.from(numbers) I'm returning an array like [ '1' , ' ' , '2']
oh you're right @HeebieGeeBee it won't matter
well, just a little replace() method extra work in :)
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 06:26
@johnnunns Array.from(arguments) might be better if you want an array fromt eh arguments passed into the function
John Nunns
@johnnunns
Mar 22 2017 06:27
actually, working on the array if it has spaces will confuse my index
Jor
@joreyesl
Mar 22 2017 06:27
also it looks like he is actually passing in a string?
John Nunns
@johnnunns
Mar 22 2017 06:27
@joreyesl yeah it's what the problem is passing in as an argument
Jor
@joreyesl
Mar 22 2017 06:29
@johnnunns ok so lets say you are passing in "1 2 3 4 5" you can convert that to number array with
var str = "1 2 3 4 5";
var arr = str.split(" ").map(function(c) { return Number(c)});
john94
@lpy1994
Mar 22 2017 06:34
anybody using VS Code as editor js ??
John Nunns
@johnnunns
Mar 22 2017 06:34
function iqTest(numbers){
  // ...
  function isOdd(num) {return num%2===1}
  var re = /\s/gi
  var actualNumbers = numbers.replace(re, '').split('')
  return actualNumbers.indexOf(actualNumbers.filter(isOdd)[0])
}

iqTest('4 2 3 4 5')
@joreyesl
that's how I've solved it here
Aditya
@adityatom
Mar 22 2017 06:35
can any one help me how to solve golf code
Jor
@joreyesl
Mar 22 2017 06:35
@johnnunns :thumbsup:
inter
@inter727
Mar 22 2017 06:41
how to 'a' to 'A' in javascript?
AKS
@amitkumarsarangi
Mar 22 2017 06:43
@inter727 toUpperCase()
Markus Kiili
@Masd925
Mar 22 2017 06:50
@joreyesl @HeebieGeeBee @devpaaji @revisualize Morning.
Joseph
@revisualize
Mar 22 2017 06:52
@Masd925 :wave:
HeebieGeeBee
@HeebieGeeBee
Mar 22 2017 06:53
@Masd925 morning
Jor
@joreyesl
Mar 22 2017 06:54
@Masd925 good evening
inter
@inter727
Mar 22 2017 06:54
@amitkumarsarangi Title case a sentence

@amitkumarsarangi function titleCase(str) {

var strArray = str.split(' ');
for(var i=0; i<strArray.length; i++){ var initial = strArray[i].charAt(0); var initialValue = strArray[i].charCodeAt(0); if(initialValue>=97 && initialValue<=122){
initial -= 32;
strArray[i].charAt(0) = initial;
}

}
str = strArray.join(' ');
return str;
}

titleCase("I'm a little tea pot");

Markus Kiili
@Masd925
Mar 22 2017 06:56
@inter727 No need to check any charcodes here. Just loop the array of words, construct a new titlecased word with string operations and assign back to the array.
John Nunns
@johnnunns
Mar 22 2017 06:58
@joreyesl I think you were definitely right. Took me some debugging but my code split 2 digit numbers up and messed up the function. so '10' would be split to [1,0]
Jor
@joreyesl
Mar 22 2017 07:01
@inter727 after you get the first character, you can use toUpperCase() to capitalize it. Also look at substring() to get the rest of the string. Then you just need to combine them back together to get what you want.
@johnnunns i see, you know you can just use .split(' '), that will split them up using the space as the delimiter . No need to use replace to get rid of the space first.
John Nunns
@johnnunns
Mar 22 2017 07:04
that would just be too easy though @joreyesl @joreyesl
:joy:
thanks man @joreyesl
CamperBot
@camperbot
Mar 22 2017 07:04
johnnunns sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 657 | @joreyesl |http://www.freecodecamp.com/joreyesl
Jor
@joreyesl
Mar 22 2017 07:07
@johnnunns np, unless you like doing things the hard way. ;)
swapnil2108
@swapnil2108
Mar 22 2017 07:07
Can anybody help me with the card sequence game cannot understand what to do
Jor
@joreyesl
Mar 22 2017 07:07
@swapnil2108 what do you have so far?
swapnil2108
@swapnil2108
Mar 22 2017 07:09

var count = 0;

function cc(card) {
// Only change code below this line
if(card == 2 || card == 3 ||card == 4 ||card == 5 || card == 6){
count = count+1;
return count+" Bet";
}
else if(card == 10 || card == 'J' ||card == "Q" || card == "K" || card == "A"){
count = count-1;
return count+" Hold";
}
else if(card == 7 || card == 8 || card == 9){
return count+" Hold";
}
else{
return "Change Me";
}

i cannot interpret the question properly
Joseph
@revisualize
Mar 22 2017 07:10
@swapnil2108 Counting Cards is a challenge where your function will receive a card parameter. You're supposed to increment or decrement the global count variable according to the card's value
If the value of the card parameter is 2, 3, 4, 5 or 6 you need to increment the global variable count.
If the value of the card parameter is 10, 'J', 'Q', 'K' or 'A' you need to decrement the global variable count.
Then the function will return a string with the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative.
The current count and the player's decision ("Bet" or "Hold") should be separated by a single space.
Markus Kiili
@Masd925
Mar 22 2017 07:11
@swapnil2108 The code needs two separate parts. Value of card changes count. Count determines return value. Don't mix them.
swapnil2108
@swapnil2108
Mar 22 2017 07:11
ohhhhhh got it thank you soo much @revisualize :D
CamperBot
@camperbot
Mar 22 2017 07:11
swapnil2108 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3570 | @revisualize |http://www.freecodecamp.com/revisualize
swapnil2108
@swapnil2108
Mar 22 2017 07:11
thank you @Masd925 :D
CamperBot
@camperbot
Mar 22 2017 07:11
swapnil2108 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 3636 | @masd925 |http://www.freecodecamp.com/masd925
Tudor Andrei Dumitrascu
@TudorAndrei
Mar 22 2017 07:21
Hello guys, for the palindrome challenge how do i replace all the symbols, can i use a regex for all of them or what?
Herman Fassett
@HermanFassett
Mar 22 2017 07:22
Yeah, 1 regex should suffice
Tudor Andrei Dumitrascu
@TudorAndrei
Mar 22 2017 07:26

function palindrome(str) {

  str.replace(/[-!$%^&*()_+|~=`{}\[\]:";'?,.]/," ");
   str.toLowerCase();
  var x=str.split(' ');
  x.reverse();
 x.join(' ');

  if(x == str)
    return true;
  return false;

}



palindrome("eye");
CamperBot
@camperbot
Mar 22 2017 07:26
:bulb: to format code use backticks! ``` more info
Markus Kiili
@Masd925
Mar 22 2017 07:26
@TudorAndrei You should look at \W and \w
Tudor Andrei Dumitrascu
@TudorAndrei
Mar 22 2017 07:26
@Masd925 what do you mean
Markus Kiili
@Masd925
Mar 22 2017 07:27
@TudorAndrei There is a metacharacter that targets all non-alphanumerics. No need to list them all.
@TudorAndrei Underscore is a slight problem that needs to be taken care of then.
Code_Minded
@mnedariya
Mar 22 2017 07:33
817d317eecb8af559b39be77577c2b2e.jpg
Markus Kiili
@Masd925
Mar 22 2017 07:35
@TudorAndrei Strings are immutable, so str.toLowerCase(); returns a new string that you don't store.
John Nunns
@johnnunns
Mar 22 2017 07:35
function noDuplicates(list){
  var splitList = list.split(',');
  return splitList.filter((elem, index, array)=> array.indexOf(elem)==index)
}
noDuplicates("list, list, hey, there")
devpaaji
@devpaaji