These are chat archives for FreeCodeCamp/HelpJavaScript

18th
Nov 2016
Nikola
@NIDZAAAAA
Nov 18 2016 00:00
@sjames1958gm i see, but i dont understand
Stephen James
@sjames1958gm
Nov 18 2016 00:00
What does the example code have?
Aleksander Gębicki
@Takumar
Nov 18 2016 00:00
@Lila-Mohamed don't put semicolon after name of function: function nextInLine(arr, item); <- remove semicolon here instead you should put {
function nextInLine(arr, item) {
Nikola
@NIDZAAAAA
Nov 18 2016 00:01
@sjames1958gm

function isLess(a, b) {
// Fix this code
if (a < b) {
return true;
} else {
return false;
}
}

// Change these values to test
isLess(10, 15);

Stephen James
@sjames1958gm
Nov 18 2016 00:01
@NIDZAAAAA And what does the example code have above that
jwalk197804
@jwalk197804
Nov 18 2016 00:02
can someone please help me with this simple javascript code challenge !! I am having a hard time with it.
Nikola Mitric
@mitric3
Nov 18 2016 00:02
@NIDZAAAAA koja je to vezba?
Nikola
@NIDZAAAAA
Nov 18 2016 00:02
@mitric3 Returning Boolean Values from Functions
Bhavik Shah
@shahbhavik01
Nov 18 2016 00:02
Hi I'm running through freeCodeCamp for javascript and need some quick help. Instructions: Change the provided string from double to single quotes and remove the escaping.
var myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";
Dan Couper
@DanCouper
Nov 18 2016 00:03
@JLuboff invert the logic, get the current time, then get hours and minutes from that. Then compare that. Otherwise (and preferably, as ideally you want this stored somewhere and actual ISO times or whatever may well be nightmarish, but are in general better to deal with), you’re going to want to store them as full date time objects. So you don’t just want the time, you also want the date. Then wherever you’re spitting the values out into, you just grab the time from there. So in the array pairs, you’d have pairs of Date objects
jwalk197804
@jwalk197804
Nov 18 2016 00:03

Assign the value 7 to variable a.

Assign the contents of a to variable b.

Can someone please help me !
Bhavik Shah
@shahbhavik01
Nov 18 2016 00:03
These are the 3 challenges. 1. Remove all the backslashes ()
  1. You should have two single quotes ' and four double quotes "
  2. Only remove the backslashes \ used to escape quotes.
Nyan9
@NyanNaing
Nov 18 2016 00:03
@shahbhavik01 you change your double quotes " " to single quotes ' ' . and don't forget to delete the escape \s
Bhavik Shah
@shahbhavik01
Nov 18 2016 00:03
I can complete one of these at a time but not all at once
@NyanNaing I did that but it only completes 1 challenge
Nyan9
@NyanNaing
Nov 18 2016 00:04
lol i know exactly what's happening
Nikola
@NIDZAAAAA
Nov 18 2016 00:04
@jwalk197804 a = 7 , b = a
Nyan9
@NyanNaing
Nov 18 2016 00:05
@shahbhavik01 you should only change the "double quotes" for your anchor tag '<a></a>'. everything else inside the anchor tag, you keep.
Lila Mohamed
@Lila-Mohamed
Nov 18 2016 00:06
@Takumar For some reason (I don't know why) it wont let me pass thru.
labanch
@labanch
Nov 18 2016 00:06
can someone explain what the x and y is in the following snippet:
return str.split('').reduce(function(x, y){
    return Math.max(x, y.length);
  }, 0);
Dan Couper
@DanCouper
Nov 18 2016 00:06
@JLuboff because if you already have date objects, it’s trivial to do myDate.getHours() or myDate.getMinutes(), whereas going the other way (build up a date object from just strings, figure out date, compare), that’s difficult. Dates/Times are almost always…difficult…shall we say...to work with, so good luck ;)
Jason Luboff
@JLuboff
Nov 18 2016 00:07
@DanCouper I think thats where I'm getting hung up, I can't seem to get a full date to work. I've tried using new Date("1/1/2016" + startTime) but that doesn't seem to work nor does Date.parse(). But it might just be that I'm tired/not feeling well and just not wrapping my head around it. But yes, I'm finding these times to be a pain heh
Bhavik Shah
@shahbhavik01
Nov 18 2016 00:08
@NyanNaing : var myStr = \"<a href='http://www.example.com' target='_blank'>Link</a>\";
Lila Mohamed
@Lila-Mohamed
Nov 18 2016 00:08
@Takumar I'm getting this Before: [1,2,3,4,5] 6 After: [1,2,3,4,5] as error
Bhavik Shah
@shahbhavik01
Nov 18 2016 00:09
@NyanNaing This doesn't work either :/
Nyan9
@NyanNaing
Nov 18 2016 00:09
@shahbhavik01 '<a href="http://www.example.com" target="_blank">Link</a>'
Mohamed Osama Khan
@Assaonator
Nov 18 2016 00:09
For Understanding Uninitialized Variables: why should a should a be defined and have a value of 6 while a = 5;
Adam
@adamakers
Nov 18 2016 00:09
anyone here good with recursion?
Mohamed Osama Khan
@Assaonator
Nov 18 2016 00:10
I don't understand that a = 5; but should have a value of 6 like what does that mean
Bhavik Shah
@shahbhavik01
Nov 18 2016 00:11
@NyanNaing Thank you so much sir
CamperBot
@camperbot
Nov 18 2016 00:11
shahbhavik01 sends brownie points to @nyannaing :sparkles: :thumbsup: :sparkles:
:cookie: 191 | @nyannaing |http://www.freecodecamp.com/nyannaing
Dan Couper
@DanCouper
Nov 18 2016 00:11
olddate = new Date(‘1/1/2016’)
new Date(old date.getTime() + minutesDifference * 60000) adds minutes
Adam
@adamakers
Nov 18 2016 00:11
trying to wrap my head around this one
function factorial(num) {
  if (num === 1) {
    return 1;
  }
  return num * factorial(num - 1);
}
console.log(factorial(5));
Nyan9
@NyanNaing
Nov 18 2016 00:11
@shahbhavik01 you understand or do you want me to explain ? :)
Dan Couper
@DanCouper
Nov 18 2016 00:12
@JLuboff you can’t add numbers to a string, you need to add to an actual date object, and you’re adding milliseconds
so need to convert to minutes/hours
@JLuboff use this: http://momentjs.com/
There is a reason it gets recommended every time people try to write date handling logic. If possible, don’t write your own, use a good library; moment is the best, though date.js is quite good
Jason Luboff
@JLuboff
Nov 18 2016 00:14
@DanCouper Awesome. I'll look at both links. Thanks. I'll see what I can do with them.
CamperBot
@camperbot
Nov 18 2016 00:14
jluboff sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 354 | @dancouper |http://www.freecodecamp.com/dancouper
Bhavik Shah
@shahbhavik01
Nov 18 2016 00:15
@NyanNaing I'm actually confused. Can you please explain if you don't mind?
Dan Couper
@DanCouper
Nov 18 2016 00:16

@adamakers

It builds up a stack of functions, all nested inside each other. Functions are just values, same as anything else, so it’s the same as passing more and more values in. Once it hits the end, it starts to evaluate from the inside out:

function(5)
// a stack of functions is built up until the number hits 1
function(5 * function(4 * function(3 * function(2 * function(1)))))
// then the stack “unwinds” from the innermost function
function(5 * function(4 * function(3 * function(2 * 1))))
function(5 * function(4 * function(3 * function(2))))
function(5 * function(4 * function(3 * 2)))
function(5 * function(4 * 6))
function(120)
120
Nyan9
@NyanNaing
Nov 18 2016 00:17
@shahbhavik01 sure thing!
Jan
@burning-monk
Nov 18 2016 00:17
@DanCouper you are missing a bracket
Adam
@adamakers
Nov 18 2016 00:18
@DanCouper I see. Yea the part that was tripping me up was the return 1 statement. But you saying that functions are just values makes total sense now
Dan Couper
@DanCouper
Nov 18 2016 00:19

this is I think a good example of recursion, someone posted in HN ages ago, I think I’ve got it right: imagine you go to a cinema where you get to sit anywhere. You go sit down while your friend gets some food. You’re not paying attention, and forget to check which row you picked. By the time she gets back, the cinema is packed and when she texts asking which row you’re in, you can’t tell her.

So, to find out, you get a piece of paper and a pen and you lean forward to the person in front. You ask them to put one tally on the piece of paper, and if they are in the front row, to pass it back, and if they aren’t in the front row they should ask the same question you just asked them of the person in front, and so on. The piece of paper moves forward through the rows (increasing the stack) until it hits the front, at which point it travels back to you (unwinding) with a tally of every row, giving you the row number.

@adamakers the return bit at the the start is critical - there needs to be an end condition, else it just goes on forever
Jan
@burning-monk
Nov 18 2016 00:20
that code snippet is awesome tried to explain this to someone recently
Nikola Mitric
@mitric3
Nov 18 2016 00:21
@NIDZAAAAA buraz jesi tu jos?
Nikola
@NIDZAAAAA
Nov 18 2016 00:21
da da
Adam
@adamakers
Nov 18 2016 00:21
@DanCouper right. I was thinking that the return 1 would just return 1, but I see that its returning the value 1, which is then multiplied by the results of the other functions
Stephen James
@sjames1958gm
Nov 18 2016 00:21
@NIDZAAAAA Did you get it? I was AFK
Nikola Mitric
@mitric3
Nov 18 2016 00:21

@NIDZAAAAA
this will work:
function isLess(a, b) {
// Fix this code
var ana = (a < b)? true : false;
return ana;
}

// Change these values to test
isLess(10, 15);

Jan
@burning-monk
Nov 18 2016 00:22
@DanCouper is it possible to see all those function calls actually?
Dan Couper
@DanCouper
Nov 18 2016 00:22
@adamakers and yeah it is because they’re just values - so that multiply is just adding values up
Stephen James
@sjames1958gm
Nov 18 2016 00:22
@NIDZAAAAA where the sample code was return a === b; your code should be return a < b;
Jan
@burning-monk
Nov 18 2016 00:22
or in general too see what is actually going on?
Dan Couper
@DanCouper
Nov 18 2016 00:22
@burning-monk yyyyeah, ish - you can put a log in, and it’ll spit them out on the console.
But that’s the issue
Adam
@adamakers
Nov 18 2016 00:22
@DanCouper cool. I'm going to try some more problems and see if I can get it
Nikola Mitric
@mitric3
Nov 18 2016 00:23
@NIDZAAAAA aj probaj meni je proslo pa da znam ako ti radi da idem dok nisam zaspao za compom :)
Walid Ashri
@walidashri
Nov 18 2016 00:23
Hi Please how to rewrite this with ternary operator?
function SeriesSum(n)
{
  let result=0;
  while(--n>=0){
  result+=(1/(1+(3*n)));
  }
return result.toFixed(2)
}
Jan
@burning-monk
Nov 18 2016 00:23
@DanCouper yeah ok but can you see what the interpreter does?
Dan Couper
@DanCouper
Nov 18 2016 00:23
@burning-monk with recursive functions, you can’t get good stacktraces. You can get the values changing, but it’s limited
this is the issue at the minute
with tail calls
they have been approved, and that will make recurive functions actually quick
it will convert them down to while loops (I assume, that’s what every other language does)
Nikola
@NIDZAAAAA
Nov 18 2016 00:24
@mitric3 brate proslo
:D
al ne znam koja je fora
Dan Couper
@DanCouper
Nov 18 2016 00:25
@burning-monk so you don’t get that big stack building up as much, it gets optimised away. But that also wipes out accurately finding errors
seeing what the interpreter does is…not fun with recurive stuff in JS
Adam
@adamakers
Nov 18 2016 00:25
@DanCouper and that analogy along with the way you wrote out those functions makes sense now. That was awesome
Dan Couper
@DanCouper
Nov 18 2016 00:25
:thumbsup: thanks @adamakers
Nikola Mitric
@mitric3
Nov 18 2016 00:25
@NIDZAAAAA
http://www.w3schools.com/js/js_comparisons.asp
guglovao pa nasao ovo, mislim da je to ternarni operator ili tako nesto, sve u svemu programiranje se dosta svodi na guglovanje ;)
Jan
@burning-monk
Nov 18 2016 00:25
@DanCouper no, I mean can you see what the interpreter does?
Adam
@adamakers
Nov 18 2016 00:25
@DanCouper thanks!
CamperBot
@camperbot
Nov 18 2016 00:25
adamakers sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 355 | @dancouper |http://www.freecodecamp.com/dancouper
Nyan9
@NyanNaing
Nov 18 2016 00:26

@shahbhavik01 so in JavaScript you need quotations (single or double) you're creating a string.
so let's say you're creating a string var :

var myString = "My dog name is Pluto";
var myString = 'My dog name is Pluto';

now you want to use quotations IN your string:

var myString = "My dog name is 'Pluto' ";
var myString = 'My dog name is "Pluto" ';

you can use this method
or you can escape by using backlashes \" \' :

var myString = "My dog name is \"Pluto\" ";
var myString = "My dog name is \'Pluto\" ';
Nikola
@NIDZAAAAA
Nov 18 2016 00:26
@mitric3 fora je bila da se samo stavi return a < b;
obrises if statment i to je to
Dan Couper
@DanCouper
Nov 18 2016 00:26
@burning-monk sort of. Try this: http://www.pythontutor.com/javascript.html#mode=edit
Nikola Mitric
@mitric3
Nov 18 2016 00:27
@NIDZAAAAA
nemam pojma ja sam zaglavio na nekoj drugoj gluposti ali reko aj da probam i proslo je ovo :D
Nikola
@NIDZAAAAA
Nov 18 2016 00:27
@mitric3 Thank you , u svakom slucaju na ulozenom trudu ;)
CamperBot
@camperbot
Nov 18 2016 00:27
nidzaaaaa sends brownie points to @mitric3 :sparkles: :thumbsup: :sparkles:
:cookie: 170 | @mitric3 |http://www.freecodecamp.com/mitric3
Dan Couper
@DanCouper
Nov 18 2016 00:28
@burning-monk ach, sorry, that wipes out the actual stack buildup
no use
Nikola
@NIDZAAAAA
Nov 18 2016 00:28
@sjames1958gm thank you.
CamperBot
@camperbot
Nov 18 2016 00:28
:star2: 4408 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
nidzaaaaa sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Nikola Mitric
@mitric3
Nov 18 2016 00:28
@NIDZAAAAA
my pleasure i hvala za brownie ;)
laku noc buraz
Nikola
@NIDZAAAAA
Nov 18 2016 00:29
Laku noc. ;) np
Dan Couper
@DanCouper
Nov 18 2016 00:29
@burning-monk problem is, there are already some optimisations done by the JS interpreter in an attempt to make the function faster, and that kills accurately describing the process
Jan
@burning-monk
Nov 18 2016 00:30
@DanCouper ah ok
Andrej G
@AndrejGalad
Nov 18 2016 00:30
Can anyone tell me what's wrong please?
Dan Couper
@DanCouper
Nov 18 2016 00:30
Ah, it’s ok actually, just playing around with it a bit more
Andrej G
@AndrejGalad
Nov 18 2016 00:30
var myStr= "I am a \"double qouted\" string inside \"double qoutes\".";
Nyan9
@NyanNaing
Nov 18 2016 00:31
[Golf Code](http://https://www.freecodecamp.com/challenges/golf-code) just killed me. Idk what happened but I got it right lol 
Stephen James
@sjames1958gm
Nov 18 2016 00:31
@NyanNaing :+1:
@AndrejGalad mispelled quotes
Dan Couper
@DanCouper
Nov 18 2016 00:31

@burning-monk You can see the number going down, then it goes back up the chain filling up the value. If you paste in the

function factorial(num) {
  if (num === 1) {
    return 1;
  }
  return num * factorial(num - 1);
}

factorial(10);

Then hit execute, it gives you all the steps, 10 num values, then it moves back up, filling in the return until it completes at step 31

Jan
@burning-monk
Nov 18 2016 00:33
@DanCouper nice thanks
CamperBot
@camperbot
Nov 18 2016 00:33
burning-monk sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 356 | @dancouper |http://www.freecodecamp.com/dancouper
Lila Mohamed
@Lila-Mohamed
Nov 18 2016 00:38
@Takumar I got it. Was missing {} closing brackets on first line. Damn, can't believe I spent an hour on that. Thanks for your help.
CamperBot
@camperbot
Nov 18 2016 00:38
lila-mohamed sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star2: 3351 | @takumar |http://www.freecodecamp.com/takumar
Allisha
@lazershark4PrimeMinister
Nov 18 2016 00:44

Returning Boolean Values from Functions:

function isEqual(a,b) {
return a === b;

}

isLess(10, 15);

Is there a bug with This challenege?

Challenge*
Margaret
@Margaret2
Nov 18 2016 00:45
what code have you tried?
@lazersharkPM
i mean the function isEqual is not supposed to be in there, you are supposed to be writing the function isLess() @lazersharkPM
Allisha
@lazershark4PrimeMinister
Nov 18 2016 00:47
Tried that :/
Nikola
@NIDZAAAAA
Nov 18 2016 00:47
@lazersharkPM you change the function name
Margaret
@Margaret2
Nov 18 2016 00:47
what did you try for isLess
Allisha
@lazershark4PrimeMinister
Nov 18 2016 00:47

function isLess(a,b) {
return a === b;

}

isLess(10, 15);

Nikola
@NIDZAAAAA
Nov 18 2016 00:47
instruction
Margaret
@Margaret2
Nov 18 2016 00:48
@lazersharkPM so that still checks if a is equal to b, you need to check if a is less than b
FreddyAl
@FreddyAl
Nov 18 2016 00:49

Im trying to add an html element using jquery.

Here is my code for the html:

<!DOCTYPE html>

<html>
<head>
<title>Result</title>
<script type='text/javascript' src='script.js'></script>
</head>
<body>
<h1></h1>
</body>
</html>

Javascript:

$(document).ready(function() {
$h1 = $("<h1>Hello</h1>")
});

Allisha
@lazershark4PrimeMinister
Nov 18 2016 00:49
@Margaret2 Ahhh, thanks!
CamperBot
@camperbot
Nov 18 2016 00:49
lazersharkpm sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:cookie: 466 | @margaret2 |http://www.freecodecamp.com/margaret2
Margaret
@Margaret2
Nov 18 2016 00:49
:D
FreddyAl
@FreddyAl
Nov 18 2016 00:49
Can anyone help me?
skratchbreaker
@skratchbreaker
Nov 18 2016 00:50

Hey guys, did I do something wrong here? I get the right answers but it is still marked as not good

var code = [];

function rot13(str) {
for (i = 0; i < str.length; i++){
var initialNum = str.charCodeAt(i);
if (str.charCodeAt(i) < 65){
code.push(String.fromCharCode(initialNum));
} else if(str.charCodeAt(i) < 97){
if (initialNum >= 78 ){
realNum = initialNum - 13;
code.push(String.fromCharCode(realNum));
} else {
realNum = initialNum + 13;
code.push(String.fromCharCode(realNum));
}
}
}

return code.join("");
}

// Change the inputs below to test
rot13("SERR YBIR?");

Margaret
@Margaret2
Nov 18 2016 00:50
@FreddyAl you want to add another h1 element, or you just want to add text inside the element?
FreddyAl
@FreddyAl
Nov 18 2016 00:51
add a h1 element
In script.js, create a variable, $h1, and set it equal to a jQuery object containing an <h1> tag with the text "Hello". The tag should be a string.
these are the instructions @Margaret2
skratchbreaker
@skratchbreaker
Nov 18 2016 00:51
@nole-codecamp I found my mistake. There is actually one parameter but 3 arguments. At first I though that all 3 arguments were part of the parameter arr.
Margaret
@Margaret2
Nov 18 2016 00:52
@FreddyAl try $h1 = $("h1").html("Hello");
Ken Haduch
@khaduch
Nov 18 2016 00:52
@skratchbreaker - you might also have a problem with the global variable code - it might be necessary to make it local to your function.
Margaret
@Margaret2
Nov 18 2016 00:53
@FreddyAl sorry, i mean $h1 = $("h1") then you can use the variable: $h1.html("Hello")
skratchbreaker
@skratchbreaker
Nov 18 2016 00:54
@khaduch Yep that was the problem. Not sure to understand though. Can you explain?
Margaret
@Margaret2
Nov 18 2016 00:54
if that doesn't work, please tell me the challenge name so i can go look at it @FreddyAl
Glauco Oliveira
@glaucodiogo
Nov 18 2016 00:55
hi guys
Margaret
@Margaret2
Nov 18 2016 00:55
:wave:
Ken Haduch
@khaduch
Nov 18 2016 00:55
@skratchbreaker - the test code runs the function a number of times, but I think that most of the time if you have a global variable, it only gets initialized once, and then the function is called multiple times, accumulating the answer(s) in the global value. In this case, your code array.
Glauco Oliveira
@glaucodiogo
Nov 18 2016 00:55
I need help
for create mad libs
FreddyAl
@FreddyAl
Nov 18 2016 00:56
It works, Im using codecademy for help. Im gonna peace on codecademy. They are messing up lol
That code worked
Margaret
@Margaret2
Nov 18 2016 00:56
oh really? great! :D
FreddyAl
@FreddyAl
Nov 18 2016 00:57
@Margaret2 Do i have to add a specific h1 element on the html document though?
skratchbreaker
@skratchbreaker
Nov 18 2016 00:57
@khaduch thanks
CamperBot
@camperbot
Nov 18 2016 00:57
skratchbreaker sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 1940 | @khaduch |http://www.freecodecamp.com/khaduch
Margaret
@Margaret2
Nov 18 2016 00:58
@FreddyAl is that what the instructions say to do?
FreddyAl
@FreddyAl
Nov 18 2016 00:58
no, heres what the instruction say to do when using jquery
$p = $("<p>I'm a new paragraph!</p>");
Margaret
@Margaret2
Nov 18 2016 00:59
so $h1 = $("<h1>Hello</h1>");
FreddyAl
@FreddyAl
Nov 18 2016 00:59
n script.js, create a variable, $h1, and set it equal to a jQuery object containing an <h1> tag with the text "Hello". The tag should be a string.
this is what the codecademy instructions say to do
Margaret
@Margaret2
Nov 18 2016 01:00
so like I did above ^
FreddyAl
@FreddyAl
Nov 18 2016 01:00
yea but not like what the example was saying at all though
I tried doing it verbatim like that and it didnt work
maybe im just not understanding the instructions @Margaret2
yea like that except it didnt work like that
Margaret
@Margaret2
Nov 18 2016 01:02
so it's still not working? do you have a link to it
FreddyAl
@FreddyAl
Nov 18 2016 01:02
yea
Margaret
@Margaret2
Nov 18 2016 01:04
@FreddyAl ok so you have to put var $h1 = $("<h1>Hello</h1>"); in the script.js tab
i think we were forgetting the var :joy: stupid us
FreddyAl
@FreddyAl
Nov 18 2016 01:06
it didnt work, do you want to dm? @Margaret2
Bayron Gutierrez Herrera
@bayronguti22hope
Nov 18 2016 01:25
Someone can help me?? i don understand this: Change the code to use the -- operator on myVar.?
MoNag1
@MoNag1
Nov 18 2016 01:26
@bayronguti22hope send your code and the challenge name?
Bayron Gutierrez Herrera
@bayronguti22hope
Nov 18 2016 01:27

var myVar = 11;

// Only change code below this line
myVar = myVar - 1;

Decrement a Number with JavaScript
MoNag1
@MoNag1
Nov 18 2016 01:28
@bayronguti22hope they want use to use the operator --
when you decrement a number, say i, doing i-- decreases the value by 1
likewise, i++ increases the value by 1
apply that logic to myVar
Littlebear2155
@Littlebear2155
Nov 18 2016 01:55
var count = 0;

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



 }
  return count + (count >0 ? "bet":"hold");
can someone help me with the return
Doug2541
@Doug2541
Nov 18 2016 01:56
Hi I'm currently stuck on "Counting Cards". Could anyone please point me in the right direction?
var count = 0;

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

  }
  if (count >= 0) {
    return count + " Bet";

  } else if (count <=1) { 
    return count + " Hold";
  }


  return "Change Me";
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(4); cc(5); cc(6);
Littlebear2155
@Littlebear2155
Nov 18 2016 01:58
mee tooo
i have no idea how to do the return part
Jenky W. Nolasco
@jenkynolasco11
Nov 18 2016 01:59
@Littlebear2155 put the return before the bracket
@Doug2541 its -= , not =-
The equal sign goes after
MoNag1
@MoNag1
Nov 18 2016 02:01
@Doug2541 also there is a problem with your if else statement
Doug2541
@Doug2541
Nov 18 2016 02:01
@jenkynolasco11 @MoNag1 thanks a lot
CamperBot
@camperbot
Nov 18 2016 02:01
doug2541 sends brownie points to @jenkynolasco11 and @monag1 :sparkles: :thumbsup: :sparkles:
:cookie: 333 | @monag1 |http://www.freecodecamp.com/monag1
:cookie: 397 | @jenkynolasco11 |http://www.freecodecamp.com/jenkynolasco11
MoNag1
@MoNag1
Nov 18 2016 02:03
They said to bet only if the count is positive. Yours will bet if the count is 0 or positive so change that. Second thing is you should hold if the count is 0 or negative (<=0)
Doug2541
@Doug2541
Nov 18 2016 02:03
Yeah your hint helped me figure it out :)
MoNag1
@MoNag1
Nov 18 2016 02:03
cool, no problem :smile: @Doug2541
Daniel
@scrandy95
Nov 18 2016 02:11
var myStr="FirstLine\n\Secondline\\rThirdLine";
Carson McKinstry
@CarsonMcKinstry
Nov 18 2016 02:11
var re = /^(1\s?)?(\(\d{3}\)|\d{3})[\s\-]?(\d{3})[\s\-](\d{4})$/;

  console.log(re.test("5555555555"));
ANyone know why this returns false?
Karan Nandha
@karann7
Nov 18 2016 02:12
stuck on word blanks
someone help me with this concecpt

You will need to use string operators to build a new string, result, using the provided variables: myNoun, myAdjective, myVerb, and myAdverb.

You will also need to use additional strings, which will not change, and must be in between all of the provided words. The output should be a complete sentence.

Joseph
@revisualize
Nov 18 2016 02:15
@scrandy95 Secondline.
@scrandy95 L
@karannandha I have additional text for that one.
Margaret
@Margaret2
Nov 18 2016 02:17
@CarsonMckinstry should there be a ? after the second [\s\-], to show it's optional
Karan Nandha
@karann7
Nov 18 2016 02:18
thank you
so what do i type
so confused
Carson McKinstry
@CarsonMcKinstry
Nov 18 2016 02:22
@Margaret2 yes there should have been :+1: thanks!
CamperBot
@camperbot
Nov 18 2016 02:22
carsonmckinstry sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:cookie: 467 | @margaret2 |http://www.freecodecamp.com/margaret2
Joseph
@revisualize
Nov 18 2016 02:22
@karannandha You construct a string using variables.
@karannandha But, those variables are actually called parameters. But, you use them just like variables.
Karan Nandha
@karann7
Nov 18 2016 02:25
so?
Joseph
@revisualize
Nov 18 2016 02:26
@karannandha
Another example of this:
function hello(fName, uName) {
    var result = ""; 
    result = "Hello " + fName + " " + uName + ", How is your day?";
    return result;
}
hello("Joseph", "@revisualize"); // "Hello Joseph @revisualize, How is your day?"
hello("Bella", "@bellaknoti"); // "Hello Bella @bellaknoti, How is your day?"
hello("Andy", "@dirn"); // "Hello Andy @dirn, How is your day?"
@karannandha Does that help?
Karan Nandha
@karann7
Nov 18 2016 02:28
yeah but how do they expect you to come up with this???
Joseph
@revisualize
Nov 18 2016 02:28
@karannandha You use the parameters for the function. You just make up a line using all of the parameters.
Margaret
@Margaret2
Nov 18 2016 02:29
@karannandha
  • So it wants you to make a sentence out of the words, "dog", "big", "ran", "quickly"
  • So a sentence for these words could be "The big dog ran quickly."
  • So how do you start building the sentence? Well first you need "The "
  • then you need to add the word "big". The word "big" is in the second place, so you can represent it using myAdjective
  • so now you would have "The " + myAdjective
  • then you will need to add a space + " ", then another word, and so on...
Somia ♡
@somiajagadish
Nov 18 2016 02:31
Hi anyone need help? Sorry if I cant help on certain things, I'm only on Java Script!
Joseph
@revisualize
Nov 18 2016 02:31
@somiajagadish Good thing you're in the HelpJavaScript and not some other room.
@somiajagadish there's also the HTML, CSS or jQuery help room.
Somia ♡
@somiajagadish
Nov 18 2016 02:33
@revisualize I'm here to help people lol but yeah its a good thing that im in the java script one!
Margaret
@Margaret2
Nov 18 2016 02:34
@revisualize dude, just looked at your github profile card, I also live in the Observable Universe, u my homie :joy:
Somia ♡
@somiajagadish
Nov 18 2016 02:35
@Margaret2 omgg i didnt know people said dude and homie here ahaha im dying
Margaret
@Margaret2
Nov 18 2016 02:35
:joy::joy:
Karan Nandha
@karann7
Nov 18 2016 02:35
can someone just give me the solution so i can backward work it
Joseph
@revisualize
Nov 18 2016 02:35
@Margaret2 HEHE.
Margaret
@Margaret2
Nov 18 2016 02:36
@karannandha what have you tried so far
Anthony
@jawaka72
Nov 18 2016 02:36
function repeatStringNumTimes(str, num) {
  // repeat after me
  str = str.repeat(num);
  if (num < 0) {
    return "";
  } 

  return str;
}
repeatStringNumTimes("abc", 3);
I need to return "" if num is not a positive number. How can I do that?
Karan Nandha
@karann7
Nov 18 2016 02:37
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
result = wordBlanks + myAdjective + myVerb + myAdverb + "" + myNoun + ",how is your day";
}
Joseph
@revisualize
Nov 18 2016 02:37
@karannandha Great. But...
dopeoplewritelikethis?
@karannandha You also don't have a return statement.
Moisés Man
@moigithub
Nov 18 2016 02:38
also remove the function name from ur contatenation
Joseph
@revisualize
Nov 18 2016 02:38
@karannandha wordBlanks isn't a variable name.
Somia ♡
@somiajagadish
Nov 18 2016 02:38
@Margaret2 because literally i feel like the only kid here lol
Joseph
@revisualize
Nov 18 2016 02:39
@moigithub How are you?
Moisés Man
@moigithub
Nov 18 2016 02:39
good :) trying to get back to coding.. been away 2 or 3 months :) @revisualize
Jordan
@jordanallain
Nov 18 2016 02:39
hello, anyone in here?
Margaret
@Margaret2
Nov 18 2016 02:39
@karannandha the instructions say you have to have stuff between the variables, so add spaces between the variables myAdjective + " " + myNoun etc
@somiajagadish haha how old are you
Somia ♡
@somiajagadish
Nov 18 2016 02:40
@Margaret2 im 13
how old are you
Margaret
@Margaret2
Nov 18 2016 02:41
oh wow that's great that you are even on here. I am 22 :D
not a kid anymore
:)
Jordan
@jordanallain
Nov 18 2016 02:41
anyone past step 261 in front end?
Joseph
@revisualize
Nov 18 2016 02:41
@jordanallain Lessons don't have numbers. What is the lesson name?
Jordan
@jordanallain
Nov 18 2016 02:41
seek and destroy
Walid Ashri
@walidashri
Nov 18 2016 02:41
@FreddyAl uu need to add jquery link
Somia ♡
@somiajagadish
Nov 18 2016 02:41
@Margaret2 Thanks :) my dad's been teaching me for the last year
CamperBot
@camperbot
Nov 18 2016 02:41
somiajagadish sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:cookie: 468 | @margaret2 |http://www.freecodecamp.com/margaret2
Jordan
@jordanallain
Nov 18 2016 02:41
oh no sorry, where do i belong
Margaret
@Margaret2
Nov 18 2016 02:41
@jordanallain yeah, the numbers also include brownie points
Jordan
@jordanallain
Nov 18 2016 02:42
brownie points?
Joseph
@revisualize
Nov 18 2016 02:42
@jordanallain Yeah... Ummm. I have but, I hate that lesson. It sucks.
Margaret
@Margaret2
Nov 18 2016 02:42
not just how many challenges you've done
Joseph
@revisualize
Nov 18 2016 02:42
about @jordanallain
CamperBot
@camperbot
Nov 18 2016 02:42
:cookie: 139 | @jordanallain |http://www.freecodecamp.com/jordanallain
Margaret
@Margaret2
Nov 18 2016 02:42
thanks @jordanallain
CamperBot
@camperbot
Nov 18 2016 02:42
margaret2 sends brownie points to @jordanallain :sparkles: :thumbsup: :sparkles:
:cookie: 140 | @jordanallain |http://www.freecodecamp.com/jordanallain
Canan Gursoy
@CananGursoy
Nov 18 2016 02:42

function bouncer(arr) {
// Don't show a false ID to this bouncer.
return arr.filter(function(arr){return arr !== false && arr !== null && arr !== 0 && arr !== "" && arr !== undefined;
});

}

Joseph
@revisualize
Nov 18 2016 02:42
@jordanallain you have 140 brownie points.
Margaret
@Margaret2
Nov 18 2016 02:42
see, I just sent you brownie points @jordanallain
Jordan
@jordanallain
Nov 18 2016 02:43
oh thanks i guess, i wish they were real brownies :)
Margaret
@Margaret2
Nov 18 2016 02:43
@jordanallain so anyway, what is your trouble with the where do you belong challenge
Somia ♡
@somiajagadish
Nov 18 2016 02:44
@jordanallain hahaha
Jordan
@jordanallain
Nov 18 2016 02:44
well i'm looping through a sorted array trying to find where to insert a number
so that it fits in sequentially
Malav Shah
@malavshahce
Nov 18 2016 02:45
challenge name : Escape Sequences in Strings. how to solve this? using "printf"
Margaret
@Margaret2
Nov 18 2016 02:45
@jordanallain what i did is go ahead and push the number in, then sort it, then just find the index where the number ends up and return that :D
Jordan
@jordanallain
Nov 18 2016 02:46
thats genius
so much easier
Margaret
@Margaret2
Nov 18 2016 02:46
Always be a #lazycoder
Jordan
@jordanallain
Nov 18 2016 02:46
haha
Joseph
@revisualize
Nov 18 2016 02:46
@CananGursoy You know.. There is a built in Boolean() object reference. Maybe look at that?
Canan Gursoy
@CananGursoy
Nov 18 2016 02:48
@revisualize I looked at Boolean() but I did not get it :(
Joseph
@revisualize
Nov 18 2016 02:49
@CananGursoy It does exactly what you're trying to build.
Marc Vazquez
@dashark69
Nov 18 2016 02:49
hi team...
has anyone tried to do:
Testing Objects for Properties

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

function checkObj(checkProp) {
// Your Code Here
var result="";
if ( myObj.hasOwnProperty (checkProp===true ))

result=myObj[checkProp];

else
{
result="Not Found";
}

   return result;  

}
// Test your code by modifying these values
checkObj("gift");
once I find that " gift " is true, I am tryin to have the function

Margaret
@Margaret2
Nov 18 2016 02:51
@CananGursoy your function need to test each item in the array, not arr itself, so use function(x) or something
MoNag1
@MoNag1
Nov 18 2016 02:51
@dashark69 remove the === true
Marc Vazquez
@dashark69
Nov 18 2016 02:51
to print what is in the myObj[gift] or myobj[checkProp]
MoNag1
@MoNag1
Nov 18 2016 02:51
.hasOwnProperty() already does that
Marc Vazquez
@dashark69
Nov 18 2016 02:52
ok @MoNag1 ill try that
MoNag1
@MoNag1
Nov 18 2016 02:52
the latter
Zhafarina Ungku
@inagreen
Nov 18 2016 02:52
Hi everyone, I am at lesson 151 Understand String Immutability. And dont understand what they want me to do. I've fixed the "Jello World" string but its still giving me errors. Can anyone help please
CamperBot
@camperbot
Nov 18 2016 02:52

welcome to FreeCodeCamp @inagreen!

Zhafarina Ungku
@inagreen
Nov 18 2016 02:52

// Setup
var myStr = "Jello World";

// Only change code below this line

myStr = "Hello World";
myStr[0] = "H";

Margaret
@Margaret2
Nov 18 2016 02:52
@dashark69 you don't need to include true, if ( myObj.hasOwnProperty(checkProp)) will automatically evaluate to true or false
Marc Vazquez
@dashark69
Nov 18 2016 02:53
@MoNag1 THANKS!!!!!!
CamperBot
@camperbot
Nov 18 2016 02:53
dashark69 sends brownie points to @monag1 :sparkles: :thumbsup: :sparkles:
:cookie: 334 | @monag1 |http://www.freecodecamp.com/monag1
Marc Vazquez
@dashark69
Nov 18 2016 02:53
SO CLOSE AND YET SO FAR... THANKS..
MoNag1
@MoNag1
Nov 18 2016 02:53
:smile:
Marc Vazquez
@dashark69
Nov 18 2016 02:53
ALSO @Margaret2 THANKS!!
CamperBot
@camperbot
Nov 18 2016 02:53
dashark69 sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:cookie: 469 | @margaret2 |http://www.freecodecamp.com/margaret2
Marc Vazquez
@dashark69
Nov 18 2016 02:53
good explanation..thanks
Margaret
@Margaret2
Nov 18 2016 02:54
@inagreen they just want you to put myStr = "Hello World";
Jordan
@jordanallain
Nov 18 2016 02:54
i always forget that .sort() needs a callback to handle numbers
Canan Gursoy
@CananGursoy
Nov 18 2016 02:54

Thanks @Margaret2 . I changed the function as below and it works now
function bouncer(arr) {
return arr.filter(function(x)
{return Boolean(x);
});

}

CamperBot
@camperbot
Nov 18 2016 02:54
canangursoy sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:cookie: 470 | @margaret2 |http://www.freecodecamp.com/margaret2
Zhafarina Ungku
@inagreen
Nov 18 2016 02:54
I did that, do you mean just to delete that myStr[0] bit?
Jordan
@jordanallain
Nov 18 2016 02:54
i'm like "10 IS MORE THAN 2!!"
Zhafarina Ungku
@inagreen
Nov 18 2016 02:54
Cool thanks!
Margaret
@Margaret2
Nov 18 2016 02:54
@CananGursoy cool trick: you can also return !!x
@inagreen yep :+1:
Zhafarina Ungku
@inagreen
Nov 18 2016 02:55
@Margaret2 thanks a bunch again
CamperBot
@camperbot
Nov 18 2016 02:55
inagreen sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:cookie: 471 | @margaret2 |http://www.freecodecamp.com/margaret2
Margaret
@Margaret2
Nov 18 2016 02:56
@jordanallain :D
MoNag1
@MoNag1
Nov 18 2016 02:56
@jordanallain to get around that you can create another function to use as the parameter for sort()
Malav Shah
@malavshahce
Nov 18 2016 02:57
var myStr = "\\ \t \t \r \n";
Challenge name : Escape Sequences in Strings
Diego Mayer
@Chrono79
Nov 18 2016 02:57
@malavshahce refresh the challenge, that seems the old version and that solution won't work now
Jordan
@jordanallain
Nov 18 2016 02:57
i'm getting the hang of nameless callbacks with fat arrow syntax
Margaret
@Margaret2
Nov 18 2016 02:58
@jordanallain yeah, they are sweet, i don't think FCC lets you use them in the challenges though :unamused:
Jordan
@jordanallain
Nov 18 2016 02:58
yeah it doesn't like ES6 stuff
Malav Shah
@malavshahce
Nov 18 2016 02:59
i refreshed it. nothing happened @Chrono79
Diego Mayer
@Chrono79
Nov 18 2016 02:59
you can use it, try writing 'esversion:6'; @Margaret2 @jordanallain
Jordan
@jordanallain
Nov 18 2016 02:59
ohh i tried 'use strict'; and it didn't like that
thanks for the tip
Slavoljub Popovic
@slavo3dev
Nov 18 2016 02:59
Just did Quote Machine app project www.nrgsportshop.com
Diego Mayer
@Chrono79
Nov 18 2016 02:59
:+1:
Margaret
@Margaret2
Nov 18 2016 02:59
ooh i will go try, do i need the quotation marks?
Mikael Lopez Figueroa
@Mikaelfigueroa
Nov 18 2016 02:59
how can i multiply strings?
Diego Mayer
@Chrono79
Nov 18 2016 02:59
@Margaret2 yes

@malavshahce what does the challenge text say?

Instructions
Assign the following three lines of text into the single variable myStr using escape sequences.

FirstLine
\SecondLine\
ThirdLine
If it doesn't say something like that, you got the old version

Malav Shah
@malavshahce
Nov 18 2016 03:02
ok! :+1: @Chrono79
i m doing new version then
Margaret
@Margaret2
Nov 18 2016 03:03
@jordanallain have you done the falsy bouncer yet
Anthony
@jawaka72
Nov 18 2016 03:05
function repeatStringNumTimes(str, num) {
  // repeat after me
  str = str.repeat(num);
  if (num < 0) {
    return "";
  }
  return str;
}
repeatStringNumTimes("abc", 3);
Can someone tell me what's wrong with my code? I have to return an empty string if num is not a positive number. Any help is much appreciated.
Malav Shah
@malavshahce
Nov 18 2016 03:05
how to solve this: myStr should have encoded text with the proper escape sequences and no spacing? @Chrono79
Joseph
@revisualize
Nov 18 2016 03:06
@malavshahce Well, you have to start with the proper text and replace the words with the corosponding escape sequences.
Margaret
@Margaret2
Nov 18 2016 03:06
@jawaka72 you need to use else, right now your function always returns the str
Diego Mayer
@Chrono79
Nov 18 2016 03:07
@malavshahce use the last line: FirstLinenewlinebackslashSecondLinebackslashcarriage-returnThirdLine replace the bold text
Margaret
@Margaret2
Nov 18 2016 03:08
@jawaka72 so if (num < 0) return an empty string, else return str
Diego Mayer
@Chrono79
Nov 18 2016 03:08
@Margaret2 no need for the else there
@jawaka72 move the if above the repeat
Anthony
@jawaka72
Nov 18 2016 03:10
wouldn't (num < 0) check if a number is positive?
Diego Mayer
@Chrono79
Nov 18 2016 03:10
@jawaka72 you can't use a negative number with repeat (that gives the error)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
Anthony
@jawaka72
Nov 18 2016 03:11
He does it again. Thank you @Chrono79 . and Thank you @Margaret2 for you helps.
CamperBot
@camperbot
Nov 18 2016 03:11
:cookie: 472 | @margaret2 |http://www.freecodecamp.com/margaret2
:star2: 2564 | @chrono79 |http://www.freecodecamp.com/chrono79
jawaka72 sends brownie points to @chrono79 and @margaret2 :sparkles: :thumbsup: :sparkles:
Margaret
@Margaret2
Nov 18 2016 03:11
@jawaka72 yeah, actually now that i look at it, i think the real problem is that you are trying to assign str.repeat back into string, when really you should just return str.repeat(num)
Anthony
@jawaka72
Nov 18 2016 03:11
The order gets me sometimes.
Joseph
@revisualize
Nov 18 2016 03:11
la la la la.
Margaret
@Margaret2
Nov 18 2016 03:12
the order was also a problem i guess
Diego Mayer
@Chrono79
Nov 18 2016 03:13
@Margaret2 https://repl.it/ERbB/3
The problem was calling repeat with an invalid argument
Margaret
@Margaret2
Nov 18 2016 03:13
@Chrono79 :+1:
Malav Shah
@malavshahce
Nov 18 2016 03:13
` var myStr = "FirstLinenewline\nbackslashSecondLinebackslash\rcarriage-returnThirdLine";
Like this @Chrono79
Diego Mayer
@Chrono79
Nov 18 2016 03:14
@malavshahce you have to replace what I marked as bold text with the right escaped sequences (look at the table provided)
Walid Ashri
@walidashri
Nov 18 2016 03:14
@Chrono79 put line 3 after the if :P
Malav Shah
@malavshahce
Nov 18 2016 03:14
i did in that way too. @Chrono79 but erro r camw
Margaret
@Margaret2
Nov 18 2016 03:14
@malavshahce so just FirstLine\n instead of FirstLinenewline
Diego Mayer
@Chrono79
Nov 18 2016 03:15
@walidashri ;)
Malav Shah
@malavshahce
Nov 18 2016 03:15
yea i did same way @Margaret2
Margaret
@Margaret2
Nov 18 2016 03:16
did you escape the backslashes? backslash = \\
Malav Shah
@malavshahce
Nov 18 2016 03:16
yea
look
thanks! @Chrono79 @Margaret2
CamperBot
@camperbot
Nov 18 2016 03:17
malavshahce sends brownie points to @chrono79 and @margaret2 :sparkles: :thumbsup: :sparkles:
:cookie: 473 | @margaret2 |http://www.freecodecamp.com/margaret2
:star2: 2565 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Nov 18 2016 03:18
:+1:
Margaret
@Margaret2
Nov 18 2016 03:18
:pizza:
Jordan
@jordanallain
Nov 18 2016 03:19
@margaret2 i think i did the falsy bouncer already yes
why do you ask?
Margaret
@Margaret2
Nov 18 2016 03:19

@jordanallain well I was just gonna say, check it out with es6 arrow functions !

function bouncer(arr) {
  return arr.filter((x) => !!x);
}

:D

Jordan
@jordanallain
Nov 18 2016 03:20
hah damn that is slick!
Margaret
@Margaret2
Nov 18 2016 03:20
:D
Malav Shah
@malavshahce
Nov 18 2016 03:20
Use the + operator to build myStr
Jordan
@jordanallain
Nov 18 2016 03:20
i haven't seen that double bang before...that just determines if it is falsy?
Malav Shah
@malavshahce
Nov 18 2016 03:20
how to do that?
Jordan
@jordanallain
Nov 18 2016 03:20
or not falsy
Margaret
@Margaret2
Nov 18 2016 03:20
!!x just returns the boolean value of x
Joseph
@revisualize
Nov 18 2016 03:21
bang bang
Jordan
@jordanallain
Nov 18 2016 03:21
he shot me down
Margaret
@Margaret2
Nov 18 2016 03:21
so if x is a truthy value, !x returns false and !!x returns true
Jordan
@jordanallain
Nov 18 2016 03:21
nice is that new to ES6?
Margaret
@Margaret2
Nov 18 2016 03:22
no that is just one of those little tricks that's nice to know :)
Jordan
@jordanallain
Nov 18 2016 03:22
thanks for the tip!
MoNag1
@MoNag1
Nov 18 2016 03:22
@malavshahce add the 2 strings that they told you to and join them with a + in between. Assign that to myStr
Malav Shah
@malavshahce
Nov 18 2016 03:22
var myStr = "This is the start. " + "This is the end.";
where's the error?
Jordan
@jordanallain
Nov 18 2016 03:23
what does the error say?
MoNag1
@MoNag1
Nov 18 2016 03:23
@malavshahce no error, refresh your page
Joseph
@revisualize
Nov 18 2016 03:23
@malavshahce With that code by itself. No error.
@malavshahce But, if you're supposed to use += then there is a lot wrong
Diego Mayer
@Chrono79
Nov 18 2016 03:24
@revisualize no, that's the text for the + challenge
Joseph
@revisualize
Nov 18 2016 03:24
@Chrono79 Ahhh.
Malav Shah
@malavshahce
Nov 18 2016 03:24
yea done!
Malav Shah
@malavshahce
Nov 18 2016 03:32
var myStr; 
myStr += "This is the first sentence. This is the second sentence.";
in this anything wwrong?
Joseph
@revisualize
Nov 18 2016 03:32
@malavshahce The first sentence is supposed to be for the first variable assignment. The second is for the +=
Malav Shah
@malavshahce
Nov 18 2016 03:33
oh yea thanks! @revisualize
CamperBot
@camperbot
Nov 18 2016 03:33
malavshahce sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 2341 | @revisualize |http://www.freecodecamp.com/revisualize
Malav Shah
@malavshahce
Nov 18 2016 03:34
i unable to get ride of this silly mistakes
:worried:
Ankit Nautiyal
@Ankitnau25
Nov 18 2016 03:38
need help for record collection problem
Joseph
@revisualize
Nov 18 2016 03:39
@Ankitnau25 What's your function?
Emily Christensen
@emmalee113
Nov 18 2016 03:39

can anyone help me with "manipulating complex objects" challenge? this is what i'm doing and i'm not sure what is wrong.

var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
// Add record here
{
"artist": "Pink Floyd",
"title": "The Wall",
"release_year": 1975,
"formats": [
"CS",
"8T",
"LP"]
}
];

Joseph
@revisualize
Nov 18 2016 03:39
@emmalee113 You're supposed to make an array of objects.
Example: [ { ... } , { ... } ]
Ankit Nautiyal
@Ankitnau25
Nov 18 2016 03:40
joseph
Joseph
@revisualize
Nov 18 2016 03:40
@emmalee113 You're missing a ,
Ankit Nautiyal
@Ankitnau25
Nov 18 2016 03:40

// Setup
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
},
"2468": {
"album": "1999",
"artist": "Prince",
"tracks": [
"1999",
"Little Red Corvette"
]
},
"1245": {
"artist": "Robert Palmer",
"tracks": [ ]
},
"5439": {
"album": "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {

return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");

i want to add tracks property to id 5439

Joseph
@revisualize
Nov 18 2016 03:41
@Ankitnau25 So, you haven't done anything.
Logan Sinclair
@LoganS1
Nov 18 2016 03:53
I need help with the "Profile Lookup" Lesson. The function always returns that the list does not have the inputted property no matter what property is inputted.
Here is my code

//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){
// Only change code below this line
  var nameCheck = false;
  var propCheck = false;

for(var x = 0; x < contacts.length; x++){
  if(firstName == contacts[x].firstName && nameCheck === false){
    nameCheck = true;
    if(contacts[x].hasOwnProperty[prop] && propCheck === false){
      propCheck = true;
    }

//     for(var o = 0; o < contacts.length; o++){
//   if(prop == contacts[x][o] && propCheck === false)
//     propCheck = true;
//   }
  }
}
  if(nameCheck === false){
    return "No such contact";
  }else if(propCheck === false){
    return "No such property";
  }else{
    return contacts[prop];
  }

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Marc Vazquez
@dashark69
Nov 18 2016 04:02
@revisualize , in the case of @emmalee113 so do we just add a ?
var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
[{"Los lobos"},
{ "The Wall"},
{"1969"},
{ ["CD", "pod", "mpeg"]},
{ "false"}
]
// Add record here
];
[ {},{},{}..]
Khensura25
@Khensura25
Nov 18 2016 04:02
hey
Marc Vazquez
@dashark69
Nov 18 2016 04:03
not sure if that make sense, since it array inside another array.. ? is that actually adding it ?
Khensura25
@Khensura25
Nov 18 2016 04:03

can someone assist me with this code : function abTest(a, b) {
// Only change code below this line

if(a && b > 0) {
return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

else {
return undefined;
}
}

it doesnt actually return keyword undefined, anyone knows why ?
Ankit Nautiyal
@Ankitnau25
Nov 18 2016 04:04

// Setup
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
},
"2468": {
"album": "1999",
"artist": "Prince",
"tracks": [
"1999",
"Little Red Corvette"
]
},
"1245": {
"artist": "Robert Palmer",
"tracks": [ ]
},
"5439": {
"album": "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {

if(prop!=="tracks" && value!=="")
collection.id[prop]=value;
if(prop=="tracks" && collection[id].hasOwnProperty("tracks")===false)
{
var a=[];
collection[id].prop=a;
collection[id].prop.push(value);

}

if(prop=="tracks" && value!=="")
collection[id].prop.push(value);

if(val==="")
delete collection.prop;

return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");

joseph helpme
abdi rahman
@abdiezy
Nov 18 2016 04:05
guys am having a little trouble with this obj assingment help
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  var lookup = {
    "alpha": 
    result="Adams",

    "bravo":
    result="Boston",

    "charlie":
    result="Chicago",

    "delta":
    result="Denver",

    "echo":
    result="Easy",

    "foxtrot":
    result="Frank"  

    };



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

// Change this value to test
phoneticLookup("charlie");
Jenky W. Nolasco
@jenkynolasco11
Nov 18 2016 04:05
@Khensura25 the first if has a problem
If (a && b > 0)
If a has a value, it will always be true, and b will only evaluate if it's greater than 0
Nicola Scaramuzzo
@muzzotech
Nov 18 2016 04:06

Having trouble with Binary Agent.
my code

function binaryAgent(str) {
  var binary = str.split(" ");
  var sentence = [];
  for(var i = 0; i < binary.length; i++){
    var letter = String.charCodeAt(binary[i]);
    sentence.push(String.fromCharCode(letter));
  }
  sentence.join("");
  return sentence;
}

binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");

response

TypeError: String.fromCharCode is not a function

HELP!!!

Khensura25
@Khensura25
Nov 18 2016 04:09
@jenkynolasco11 thanks, I changed that too, and still nothing
CamperBot
@camperbot
Nov 18 2016 04:09
khensura25 sends brownie points to @jenkynolasco11 :sparkles: :thumbsup: :sparkles:
:cookie: 398 | @jenkynolasco11 |http://www.freecodecamp.com/jenkynolasco11
Jenky W. Nolasco
@jenkynolasco11
Nov 18 2016 04:11
Did you do: if (a > 0 && b > 0)
?
Khensura25
@Khensura25
Nov 18 2016 04:14
@jenkynolasco11 the instructions are :
Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.
Its working working now, but I have "null" keep popping up for when my if statement is executed. I dont know how to fix that error @jenkynolasco11
Jordan
@jordanallain
Nov 18 2016 04:15
you don't want && if its supposed to be or
you want ||
if (a < 0 || b < 0)
Jenky W. Nolasco
@jenkynolasco11
Nov 18 2016 04:16
It should work with && if both are supposed to be positive
@Khensura25 take off the else, just return undefined, or don't return anything at all... it should return undefined both ways
Khensura25
@Khensura25
Nov 18 2016 04:17
@jordanallain thanks! that worked and thanks Jenky as well @jenkynolasco11
CamperBot
@camperbot
Nov 18 2016 04:17
:cookie: 141 | @jordanallain |http://www.freecodecamp.com/jordanallain
khensura25 sends brownie points to @jordanallain and @jenkynolasco11 :sparkles: :thumbsup: :sparkles:
:warning: khensura25 already gave jenkynolasco11 points
comaeternal
@comaeternal
Nov 18 2016 04:21
I'm working on the falsy Bouncer challenge and we are suppose to use the boolean object. I keep reading the description on MDN and still don't understand how to use it. Can anyone explain how to use it correctly. Thanks
Jim Wallace
@reoski
Nov 18 2016 04:26
can anyone provide help with the Queue lesson "stand in line"??
Cole Maly
@malycole
Nov 18 2016 04:26
Would anyone be able to help me implement my API in the random quote machine?
Marc Vazquez
@dashark69
Nov 18 2016 04:27
@emmalee113 where you able to solve it ? .. i am also kinda of stuck...

var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
// Add record here

{"artist":"Los lobos"},
{"title": "The Wall"},
{"release_year": 1969},
{"formats":["CD", "pod", "mpeg"]},
{ "gold":false}

];
Jim Wallace
@reoski
Nov 18 2016 04:31
Can anyone assist with the Javscript lesson "stand in line" about queue() ??
Joseph
@revisualize
Nov 18 2016 04:39
@reoski I can.
Sup?
@reoski So, you understand the basic idea of a Queue. First In First Out?
Lila Mohamed
@Lila-Mohamed
Nov 18 2016 04:41

This should be easy but I'm missing it. Can anyone see where I went wrong. ```function welcomeToBooleans() {

// Only change code below this line.
function welcomeToBooleans()
return false; // Change this line
return false;
// Only change code above this line.
}
```

Aldair
@ald1413
Nov 18 2016 04:42

Hello can anyone help me with the checkforpalindromes challenge?


function palindrome(str) {
  // Good luck!
  str = str.toLowerCase();
  str = str.split("");
  if (str.reverse().join("")!==str) {
  return str.replace("[\\W]_|\g", "")===str.reverse().join("");
  }
}



palindrome("eye");

I dont know how to utilize replace in this case, for example I know I have to replace it if the array is not a palindrome, but how do I use it to get rid of the non-alphanumeric characters?

gari3d
@gari3d
Nov 18 2016 04:44
how to find the largest number in object literal?
Aldair
@ald1413
Nov 18 2016 04:49
@gari3d what challenge?
Alex Arnold
@laxiyo
Nov 18 2016 04:51
hey i'm having trouble iwth the title case sentence
anyone know why that doesn't capitalize the first letter of each word? they are all still lowercase
Coy Sanders
@coymeetsworld
Nov 18 2016 04:54
@Lila-Mohamed im not sure what the challenge is but you have 2 return statements, you only would need 1 as that 2nd one would never execute
and im sure you have to return something other than just false
kunal singh
@jmvictor5656
Nov 18 2016 04:56
how to count the remaing interval of Time using setInterval();
Lila Mohamed
@Lila-Mohamed
Nov 18 2016 04:57
@coymeetsworld It's Understanding Boolean Values. Instructions are Modify the welcomeToBooleans function so that it returns true instead of false when the run button is clicked. welcomeToBooleans() should return true. I've spent an hour trying, I'm soo stuck on what's wrong.
Sabrina Tee
@sabbyt
Nov 18 2016 04:58
Hi all, having trouble with the Falsy Bouncer challenge - how do i detect null values without using ===
James Moore
@James-N-M
Nov 18 2016 04:58
Hey guys anyone can help me out with a algorith mquestion
Coy Sanders
@coymeetsworld
Nov 18 2016 04:58
@Lila-Mohamed you need to return true, not false :)
and you only need one line
one return line i mean
Sabrina Tee
@sabbyt
Nov 18 2016 04:59
which one @James-N-M
Alex Arnold
@laxiyo
Nov 18 2016 05:00
thanks for help all!!
Coy Sanders
@coymeetsworld
Nov 18 2016 05:00
you could do an if statement with just the variable inside @sabbyt
if (value) { 

}
null evaluates to false
James Moore
@James-N-M
Nov 18 2016 05:00
@sabbyt The truncate string
Is the 5th provide input a typo ?
A- becomes A...
Figured it would be A-...
Lila Mohamed
@Lila-Mohamed
Nov 18 2016 05:01
@coymeetsworld This worked and I had to add {} too. Whew! Thanks a lot!
CamperBot
@camperbot
Nov 18 2016 05:01
lila-mohamed sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 1546 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
Nov 18 2016 05:02
oh i missed that @Lila-Mohamed, you put the function declaration twice, first time had the bracket 2nd time didn't
just FYI to format your code the ``` need to be on separate lines
Lila Mohamed
@Lila-Mohamed
Nov 18 2016 05:03
@coymeetsworld I was wondering why ``` wasn't working correctly. No one let me know. Thanks!
CamperBot
@camperbot
Nov 18 2016 05:03
lila-mohamed sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:warning: lila-mohamed already gave coymeetsworld points
Coy Sanders
@coymeetsworld
Nov 18 2016 05:03
no problem
Joseph
@revisualize
Nov 18 2016 05:04
la la la la
Solomon B
@ssbothwell
Nov 18 2016 05:05
im so close to finishing the last advanced algorithms challenge!
this one is really hard
Alex Arnold
@laxiyo
Nov 18 2016 05:05
change your name to girls name for help
James Moore
@James-N-M
Nov 18 2016 05:05
nvm i forgot u still gotta splice the for the second case <= 3
Solomon B
@ssbothwell
Nov 18 2016 05:05
had to do a lot of researching
is anyone around who has solved it? i have a few questions
pairwise exercise
Coy Sanders
@coymeetsworld
Nov 18 2016 05:09
whats up @ssbothwell
Solomon B
@ssbothwell
Nov 18 2016 05:10
i'm using a hashtable to find all the pairs
which works really well and fast
but it trips out when theres duplicates of an element in the array
i should just paste the code i suppose
Coy Sanders
@coymeetsworld
Nov 18 2016 05:11
are you adding the results to the hashtable?
or converting the array you need to process into one? by hashtable do you mean just a object?
Solomon B
@ssbothwell
Nov 18 2016 05:12
yeah its technically just an object
Sabrina Tee
@sabbyt
Nov 18 2016 05:13
@coymeetsworld that doesnt seems to be working function bouncer(arr) { arr.filter(function(val, index) { if (val) { return val; } }); return arr; }
Solomon B
@ssbothwell
Nov 18 2016 05:13
sorry i have a few versions im trying to make a concise gist page that shows whats going on
give me a minute
gari3d
@gari3d
Nov 18 2016 05:14
@Aldair: like if i have var obj = {
key: [1, 2, 4]
};
Coy Sanders
@coymeetsworld
Nov 18 2016 05:14
Sabrina Tee
@sabbyt
Nov 18 2016 05:14
thank you @coymeetsworld !!!
CamperBot
@camperbot
Nov 18 2016 05:14
sabbyt sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 1547 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
Nov 18 2016 05:14
you have to set arr to your arr.filter function, you also don't need the index argument as you're not explicitly using it in the callback
ah ok haha np
gari3d
@gari3d
Nov 18 2016 05:16
how to find the largest number in object literal for var obj = {
key: [1, 2, 4]
};
so i create the hashTable object with arr values as keys and arr index as values. then check if arg - arr[i] is in the hashtable
if it is then i push to the results array
but notice i had to also throw in a second conditional: arr[i] != i. without that it will push the same element from arr if the index plus the value equals the target
Coy Sanders
@coymeetsworld
Nov 18 2016 05:20
why have a hashtable in the first place @ssbothwell? I'm not sure if i follow
Coy Sanders
@coymeetsworld
Nov 18 2016 05:21
if this is for dealing with duplicates there are other ways
Solomon B
@ssbothwell
Nov 18 2016 05:21
well its a fast way to check for pairs that sum to the target
that article explains it
sorry i'm not doing a great job explaining myself or the code.
Coy Sanders
@coymeetsworld
Nov 18 2016 05:23
that doesn't factor in duplicates it seems
Solomon B
@ssbothwell
Nov 18 2016 05:23
no it doesn't
thats what i'm trying to figure out
Coy Sanders
@coymeetsworld
Nov 18 2016 05:24
you could use the indexOf method for array
Solomon B
@ssbothwell
Nov 18 2016 05:24
yeah i was thinking that would fit into it somehow
Coy Sanders
@coymeetsworld
Nov 18 2016 05:25
that would work if you kept your results in an array
like if you had (3,x,5,x,x,3) and 8 once you get to the last 3 you could check if 3 is already in your array
if is don't add it again
Solomon B
@ssbothwell
Nov 18 2016 05:26
hmm
Coy Sanders
@coymeetsworld
Nov 18 2016 05:26
in this way you're keeping track of values, not indexes
then, you would use indexOf method because indexOf would show the first occurance
i didn't do it this way but its just a thought
Solomon B
@ssbothwell
Nov 18 2016 05:28
thanks. i'll noodle around with it some more. this seemed like an interesting way to solve the exercise but its really hard to keep the whole thing in my head
Coy Sanders
@coymeetsworld
Nov 18 2016 05:28
thats why its an advanced and optional challenge :)
Solomon B
@ssbothwell
Nov 18 2016 05:28
:D
this is the last algorithm challenge i have left
i really enjoy working on them
more then the projects lol
Coy Sanders
@coymeetsworld
Nov 18 2016 05:30
yeah it depends, getting features to work on your projects are nice though, get to see something more tangible
Solomon B
@ssbothwell
Nov 18 2016 05:32
yeah thats true. i tihnk i just like puzzles
Gabriel
@gabby4hi
Nov 18 2016 05:33
pls someone help me out with this

var count = 0;

function cc(card) {
// Only change code below this line

switch(card) {
case 2:
case 3:
case 4:
case 5:
case 6:
result = ++count + " Bet";
break;

case 7:
case 8:
case 9:
result = count + " Hold";
 break;

case 10:
case "A":
case "J":
case "Q":
case "K":
result = --count + " Hold";
 break;

case 2:
case "J":
case 9:
case 2:
case 7:
result = ++count + " Bet";
 break;




}

/*
if(test for count if its higher than zero)
  return count plush Bet
else return count plus Hold
*/

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

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

Cards Sequence 2, 2, 10 should return "1 Bet" this one has been refused to mark good, how do i go about this
Abhisek Pattnaik
@abhisekp
Nov 18 2016 05:36
@gabby4hi
```js     [shift + enter for newline]
<code here>
```
Coy Sanders
@coymeetsworld
Nov 18 2016 05:39
@gabby4hi this section, will basically never execute so it can be removed:
case 2:
case "J":
case 9:
case 2:
case 7:
result = ++count + " Bet";
 break;
also you don't necessarily print out Hold or Bet based on the card you just saw
so you should remove that from the case/switch statement
you want to look at the card, modify the count (if applicable), and then after that determine whether or not you should bet or hold
Gabriel
@gabby4hi
Nov 18 2016 05:43
@coymeetsworld so how do i modify the when i know that is either it increment or decrement
Coy Sanders
@coymeetsworld
Nov 18 2016 05:43
you had that part right, using the ++ or -- operator
thats all you should be doing in the case/switch statement, modifying the count variable if it needs to be modified
determining whether you bet or hold comes after the case/switch statement
Gabriel
@gabby4hi
Nov 18 2016 05:47
@coymeetsworld so wat should i do in the case of this Cards Sequence 2, J, 9, 2, 7 should return "1 Bet"
this are multiply of hold and bet result am just confused in this aspect
Coy Sanders
@coymeetsworld
Nov 18 2016 05:50
you're already handling those cases above @gabby4hi
the way your code works those lines i highlighted will never get executed
Reggie
@ReggieSibley
Nov 18 2016 05:50
can someone help me with ordering a set of products by price using javascript?
<div class="col-md-3 col-sm-3 col-xs-6">
                    <p class="pTitle more" id="product1 p-1">Product Title 1</p>
                    <p class="pPrice">Starting at $500</p>
                    <img src="img/cereal_b.jpg" alt="cereal" id="p-1" class="cereal more">
                    <br>
                    <p class="pDetails">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
                    </p>
                    <br>
                    <a>Learn More</a>
                </div>
                <div class="col-md-3 col-sm-3 col-xs-6">
                    <p class="pTitle more" id="product2 p-2">Product Title 2</p>
                    <p class="pPrice">Starting at $500</p>
                    <img src="img/flower_b.jpg" alt="flower" id="p-2" class="flower more">
                    <br>
                    <p class="pDetails">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
                    </p>
                    <br>
                    <a>Learn More</a>
                </div>
                <div class="col-md-3 col-sm-3 col-xs-6">
                    <p class="pTitle more" id="product3 p-3">Product Title 3</p>
                    <p class="pPrice">Starting at $500</p>
                    <img src="img/machine_b.jpg" alt="machine" id="p-3" class="machine more">
                    <br>
                    <p class="pDetails">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
                    </p>
                    <br>
                    <a>Learn More</a>
                </div>
<select>
                        Filter By:
                        <option>All</option>
                        <option>Less Than $500</option>
                        <option>From $500 to $1000</option>
                        <option>From $1000 to $2000</option>
                        <option>$2000 or more</option>
                    </select>
heres the select element
Coy Sanders
@coymeetsworld
Nov 18 2016 05:52
you could use jQuery to grab the values from the HTML code @ReggieSibley
Reggie
@ReggieSibley
Nov 18 2016 05:52
i have to use pure javascript :/
unfortunately
and i dont know how to do so
do you?
Coy Sanders
@coymeetsworld
Nov 18 2016 05:53
well you could do that too
Reggie
@ReggieSibley
Nov 18 2016 05:53
so i grab the values then what
Coy Sanders
@coymeetsworld
Nov 18 2016 05:54
you would need to parse out the value from the string, like if you had "Starting at $500", you need to convert that to 500
Karan Nandha
@karann7
Nov 18 2016 05:55
please help
Call the processArg function with an argument of 7 and assign its return value to the variable processed.
stuck on this processArg
var processed = 2;
function processArg() {
var processed = processarg();
}
Coy Sanders
@coymeetsworld
Nov 18 2016 05:56
do you need to order or filter it @ReggieSibley ?
Reggie
@ReggieSibley
Nov 18 2016 05:56
fitler
filter
and hide the elements that dont meet the criteria selected
Coy Sanders
@coymeetsworld
Nov 18 2016 05:57
yeah thats not ordering so nvm what i said :)
i thought you mean rearrange, which would be conceivably harder without using an external library or framework
Reggie
@ReggieSibley
Nov 18 2016 05:57
do you know how to filter it?
Coy Sanders
@coymeetsworld
Nov 18 2016 05:57
you would still need to convert the values down to a number and evaluate
then if it meets the criteria of what you're filtering then you could apply a class to the item, and that class could have css used to hide the content
if you wanted to show the item again you could remove said class
Reggie
@ReggieSibley
Nov 18 2016 05:59
ok, ill give it a shot. could u possibly whip together a codepen?
k.vincent
@bobKasbi
Nov 18 2016 06:10
@RegYou dont need to convert... just add a value attribute to option <option value="500">$500</option> than grap the value of the option and use it in your script
Reggie
@ReggieSibley
Nov 18 2016 06:12
@bobKasbi so ive done that part, i just dont know now how i should arrange the script
k.vincent
@bobKasbi
Nov 18 2016 06:12
@ReggieSibley or use HTML 5 data attribute e.g. data-range="500"
@ReggieSibley give you select element a class an get its value
Reggie
@ReggieSibley
Nov 18 2016 06:13
ok did that
var productPrice = document.getElementById("productPricings").value
then?
k.vincent
@bobKasbi
Nov 18 2016 06:13
@ReggieSibley <select class="my-range">......
Reggie
@ReggieSibley
Nov 18 2016 06:14
yeah i gave it an id productPricings
ill change to my-range
for clairty
then i need like an if statement?
k.vincent
@bobKasbi
Nov 18 2016 06:17
@ReggieSibley var x = document.getElementsByClassName("my-range"); you can also use id. But using in class is much better...
Reggie
@ReggieSibley
Nov 18 2016 06:17
ok i've done this step already. what now?
k.vincent
@bobKasbi
Nov 18 2016 06:17
@ReggieSibley yes, if statement or switch
@ReggieSibley it depends on your HTML structure of the content
@ReggieSibley first change the content of the HTML you do have... I see that you have the same content for all elements as example
Reggie
@ReggieSibley
Nov 18 2016 06:22
yeah i did that
Gabriel
@gabby4hi
Nov 18 2016 06:23
@coymeetsworld i am trying to use if and else if method for it am still getting still uncompleted work for it
if(card == 2 || card == 3 || card == 4 || card == 5 || card == 6){

  return ++count + " Bet";

}
  else if(card == 7 || card == 8 || card == 9){
    return count + " Hold";

  }
else if(card == 10 || card == "A" || card == "J" || card == "K" || card == "Q"){
     return --count + " Hold";
}
  else {

    return --count + " Hold";
  }
/*
if(test for count if its higher than zero)
  return count plush Bet
else return count plus Hold
*/
return ++count + " Bet";
// Only change code above this line
}
k.vincent
@bobKasbi
Nov 18 2016 06:24
@ReggieSibley give the three diferrent DIVs three different classes and change the positions depending on the selections
@ReggieSibley class="range-500", class="range-1000", class="range-2000" etc
Reggie
@ReggieSibley
Nov 18 2016 06:26
ok did that, do i put an onclick on the select elements?
to activate my function
Nick Garcia
@NicksIdeaEngine
Nov 18 2016 06:26
Is anyone up for checking out my weather app? I used XMLHttpRequest for the weather data. Couldn't figure out how to use it for getting the IP address, though. http://codepen.io/NicksIdeaEngine/pen/gLLYea
Coy Sanders
@coymeetsworld
Nov 18 2016 06:26
@gabby4hi ok you took a step back, what happened to the case/switch statement? that part was fine
also you're still making same mistake of trying to do both changing the count variable and returning a result at the same time, you don't want to do it that way
you need to evaluate the card first, THEN determine what to print Bet or Hold
k.vincent
@bobKasbi
Nov 18 2016 06:28
@ReggieSibley you can make it easier first and just hide the DIVs which aren't selected
@ReggieSibley and keep the selected one, so that the user can just see the one which selected
Reggie
@ReggieSibley
Nov 18 2016 06:29
its supposed to default to all
Gabriel
@gabby4hi
Nov 18 2016 06:29
@coymeetsworld am i think we discuss this better later off for class , i will give a private chat and thanks for the time well spent , i think am getting it
CamperBot
@camperbot
Nov 18 2016 06:29
gabby4hi sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 1548 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
k.vincent
@bobKasbi
Nov 18 2016 06:29
@ReggieSibley but this hint wont't be perfect
Reggie
@ReggieSibley
Nov 18 2016 06:30
huh?
k.vincent
@bobKasbi
Nov 18 2016 06:32
@ReggieSibley I mean hide/show - my idea - won't be perfect but would give you first solution
@ReggieSibley you should write a sort() function for example which does the reorder
Reggie
@ReggieSibley
Nov 18 2016 06:45
my page is only reading the value of the first option element on page load. but when i click a different option it does not read the value
why is that
Lila Mohamed
@Lila-Mohamed
Nov 18 2016 06:54

Anyone see what is wrong? This is Use Conditional Logic with If Statements. Instr. Create an if statement inside the function to return "Yes, that was true" if the parameter wasThatTrue is true and return "No, that was false" otherwise. ``` // Example
function ourTrueOrFalse(isItTrue) {
if (isItTrue) {
return "Yes, it's true";
}
return "No, it's false";
}

// Setup

function trueOrFalse(wasThatTrue) {

// Only change code below this line.
if (wasThatTrue){
return "Yes, it's true";
}
return "No, it's false"; {
}

// Only change code above this line.

}

// Change this value to test
trueOrFalse(true); ```

kirbyedy
@kirbyedy
Nov 18 2016 06:56
@Lila-Mohamed is your text correct ?
return "Yes, it's true";
Jax
@jax11000
Nov 18 2016 06:57
not really understanding this twitch.tv api thing,
how does this new link thing they give us work?
kirbyedy
@kirbyedy
Nov 18 2016 06:57
@Lila-Mohamed instruction says: Create an if statement inside the function to return "Yes, that was true" if the parameter wasThatTrue is true and return "No, that was false" otherwise.
Lila Mohamed
@Lila-Mohamed
Nov 18 2016 06:57
@kirbyedy 3 lines are correct but it's looking for this: trueOrFalse(true) should return "Yes, that was true"
trueOrFalse(false) should return "No, that was false"
kirbyedy
@kirbyedy
Nov 18 2016 06:59
@Lila-Mohamed but you did not write the text as the instruction says
and you dont need those { } after no that was false
k.vincent
@bobKasbi
Nov 18 2016 07:05
@ReggieSibley you have to use the eventhandler onchange
Reggie
@ReggieSibley
Nov 18 2016 07:05
yeah i figured it out
thanks alot @bobKasbi
CamperBot
@camperbot
Nov 18 2016 07:05
reggiesibley sends brownie points to @bobkasbi :sparkles: :thumbsup: :sparkles:
:cookie: 124 | @bobkasbi |http://www.freecodecamp.com/bobkasbi
Lila Mohamed
@Lila-Mohamed
Nov 18 2016 07:06
@kirbyedy Got it! I did not write the same words as instructions. Thank you! :)
CamperBot
@camperbot
Nov 18 2016 07:06
lila-mohamed sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:star2: 1547 | @kirbyedy |http://www.freecodecamp.com/kirbyedy
Reggie
@ReggieSibley
Nov 18 2016 07:21
function filterPricing() {
       var myRange = document.getElementById("myRange").value
       console.log(myRange);
       if (myRange < 500) {
           document.getElementById("firstP").style.visibility = "hidden";

       } else if(myRange > 500 && myRange <= 1000) {
         document.getElementById("firstP").style.visibility = "hidden";
         document.getElementById("secondP").style.visibility = "hidden";
         document.getElementById("thirdP").style.visibility = "hidden";
       }else if(myRange >= 1000 && myRange <= 2000) {
         document.getElementById("firstP").style.visibility = "hidden";
         document.getElementById("thirdP").style.visibility = "hidden";
         document.getElementById("fourthP").style.visibility = "hidden";
       } else {
         document.getElementById("firstP").style.visibility = "visible";
         document.getElementById("secondP").style.visibility = "visible";
         document.getElementById("thirdP").style.visibility = "visible";
         document.getElementById("fourthP").style.visibility = "visible";
       }
       return myRange;

   }
So im trying to hide and show objects based on there value, it works up until the second else if. at that point it hides everything. can someone tell me a simpler way of doing this beacuse i know this is not DRY code.
Brian
@sludge256
Nov 18 2016 07:21
Your conditions overlap.
Reggie
@ReggieSibley
Nov 18 2016 07:25
yeah how can i fix
im confused
Brian
@sludge256
Nov 18 2016 07:25
What is the point of the second else if?
There's only one id difference between it and the first one
k.vincent
@bobKasbi
Nov 18 2016 07:27
@ReggieSibley How does your HTML looks like now?
@ReggieSibley The script won't work this way
Reggie
@ReggieSibley
Nov 18 2016 07:29
looks the same
im trying to just make a the stuff appear and reappear
based on price
Reggie
@ReggieSibley
Nov 18 2016 07:38
whoever can write me up a codepen that works i will give them $20 on paypal
real talk
k.vincent
@bobKasbi
Nov 18 2016 07:41
@ReggieSibley how are assigning the eventhandler to the select field?
Reggie
@ReggieSibley
Nov 18 2016 07:41
using onchange
k.vincent
@bobKasbi
Nov 18 2016 07:42
@ReggieSibley I know.. but pl. drop it again
Reggie
@ReggieSibley
Nov 18 2016 07:42
drop what
copy it?
josephinemonica
@josephinemonica
Nov 18 2016 07:47
Hi, I tried using jquery to retrieve some data . I tried this example http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_ajax_post
and I copied it to codepen, with some change
but it can't work
please help , I don't know what I did wrong , as I only copied , and change the url to absolute url
k.vincent
@bobKasbi
Nov 18 2016 07:48
@ReggieSibley first this should be : var myRange = document.getElementById("myRange");
var strUser = myRange.options[myRange.selectedIndex].value;
josephinemonica
@josephinemonica
Nov 18 2016 07:48
    $("button").click(function(){
        $.post("http://www.w3schools.com/jquery/demo_test_post.asp",
        {
          name: "Donald Duck",
          city: "Duckburg"
        },
        function(data,status){
            alert("Data: " + data + "\nStatus: " + status);
        });
    });
});
Reggie
@ReggieSibley
Nov 18 2016 07:49
ok then what
josephinemonica
@josephinemonica
Nov 18 2016 07:50
Please help me what did I do wrong, nothing popped out when I click the button
I already added the jquery library
k.vincent
@bobKasbi
Nov 18 2016 07:51
@ReggieSibley and this id cant be found in your HTML firstP
I can't find it
Ayush Bahuguna
@relentless-coder
Nov 18 2016 07:51
Hi, I am supposed to make first letter of every word toUpperCase
function titleCase(str) {
str = str.toLowerCase();
var strArr = str.split(' ');
for(var i = 0; i < strArr.length; i++) {
strArr[i].replace(strArr[i].charAt(0), strArr[i].charAt(0).toUpperCase());
}
return strArr.join(' ');
}
function titleCase(str) { str = str.toLowerCase(); var strArr = str.split(' '); for(var i = 0; i < strArr.length; i++) { strArr[i].replace(strArr[i].charAt(0), strArr[i].charAt(0).toUpperCase()); } return strArr.join(' '); }
but it is not working, nor am I getting any error.
Coy Sanders
@coymeetsworld
Nov 18 2016 07:52
@josephinemonica you have a cross-origin issue
hit F12 and look at the console
Reggie
@ReggieSibley
Nov 18 2016 07:52
@bobKasbi can u please just rewrite the code
@bobKasbi your confusing me.
Ayush Bahuguna
@relentless-coder
Nov 18 2016 07:53
ookay it worked
josephinemonica
@josephinemonica
Nov 18 2016 07:53
@coymeetsworld Hm maybe my keyboard function differently , F12 it to change my screen brightness
@coymeetsworld can you please elaborate more
Coy Sanders
@coymeetsworld
Nov 18 2016 07:53
hmm F12 on most browsers should open up the webtools
josephinemonica
@josephinemonica
Nov 18 2016 07:54
@coymeetsworld i'm using code pen btw
Coy Sanders
@coymeetsworld
Nov 18 2016 07:54
this is the error on the console you get when you push the button:
XMLHttpRequest cannot load http://www.w3schools.com/jquery/demo_test_post.asp. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://s.codepen.io' is therefore not allowed access.
josephinemonica
@josephinemonica
Nov 18 2016 07:54
@coymeetsworld oh ok I have opened the console
k.vincent
@bobKasbi
Nov 18 2016 07:54
@ReggieSibley when I run the script using your HTML following shows up: Cannot read property 'style' of null(…)
Coy Sanders
@coymeetsworld
Nov 18 2016 07:55
ok do you see that error?
josephinemonica
@josephinemonica
Nov 18 2016 07:55
@coymeetsworld So is the oproblem because of I'm using codepen?
Coy Sanders
@coymeetsworld
Nov 18 2016 07:55
sort of, the problem is the resource doesn't allow you to use it anywhere besides within w3schools
k.vincent
@bobKasbi
Nov 18 2016 07:55
and it affects the id: firstP - document.getElementById("firstP").style.visibility = "visible";
Coy Sanders
@coymeetsworld
Nov 18 2016 07:55
i wouldn't bother with copying the example into codepen, you don't need it for any of the projects or whatever
what are you trying to do @josephinemonica ?
Ryan Ledford
@rledford
Nov 18 2016 07:56
@relentless-coder put the new strings in a new list, join, and return
josephinemonica
@josephinemonica
Nov 18 2016 07:57
@coymeetsworld I'm trying to learn how to get API for the random quotes machine
@coymeetsworld so I'm trying the basic ones first
@coymeetsworld I hope I'm heading to the right direction
Ryan Ledford
@rledford
Nov 18 2016 07:58
@relentless-coder calling replace returns a new string it does not change the source string you called it on.
Coy Sanders
@coymeetsworld
Nov 18 2016 07:58
have you done the FCC lessons on JSON APIs and AJAX @josephinemonica ?
josephinemonica
@josephinemonica
Nov 18 2016 07:58
@coymeetsworld Yes I did it
Coy Sanders
@coymeetsworld
Nov 18 2016 07:59
that w3schools example is for posting also, youre not going to be posting for these challenges just need to make GET requests
josephinemonica
@josephinemonica
Nov 18 2016 07:59
@coymeetsworld but the problem is , for example I want to use this API http://forismatic.com/en/api/
ilkanatabay
@ilkanatabay
Nov 18 2016 07:59

function updateRecords(id, prop, value) {
var tracks = collection[id]["tracks"];
if(tracks == undefined && prop == "tracks"){
tracks = new Array();
}
}

Why this code above doesnt work;
But this one below works??

function updateRecords(id, prop, value) {

if(collection[id]["tracks"] == undefined && prop == "tracks"){ 
       collection[id]["tracks"] = new Array();
}

}

josephinemonica
@josephinemonica
Nov 18 2016 08:00
@coymeetsworld The website says that : POST:
method=getQuote&key=457653&format=xml&lang=en
@coymeetsworld I have no idea what that is, I thought it is a post method
ilkanatabay
@ilkanatabay
Nov 18 2016 08:02

'''
var code = formatted;
function updateRecords(id, prop, value) {
var tracks = collection[id]["tracks"];
if(tracks == undefined && prop == "tracks"){
tracks = new Array();
}
}
'''

Why this code above doesnt work;
But this one below works??

'''
var code = formatted;
function updateRecords(id, prop, value) {
if(collection[id]["tracks"] == undefined && prop == "tracks"){
collection[id]["tracks"] = new Array();
}
}
'''

CamperBot
@camperbot
Nov 18 2016 08:02
:bulb: to format code use backticks! ``` more info
josephinemonica
@josephinemonica
Nov 18 2016 08:02
@coymeetsworld In the FCC lessons on JSON APIs and AJAX, it already has the url for json.. but here, I'm not very sure. It looks like I need to post the key to get the data
ilkanatabay
@ilkanatabay
Nov 18 2016 08:02
var code = formatted;
function updateRecords(id, prop, value) {
var tracks = collection[id]["tracks"];
if(tracks == undefined && prop == "tracks"){
tracks = new Array();
}
}
Why this code above doesnt work;
But this one below works??
var code = formatted;
function updateRecords(id, prop, value) {
if(collection[id]["tracks"] == undefined && prop == "tracks"){
collection[id]["tracks"] = new Array();
}
}
Coy Sanders
@coymeetsworld
Nov 18 2016 08:02
not too familiar with that api @josephinemonica, but it says you can use get or post
josephinemonica
@josephinemonica
Nov 18 2016 08:02
@coymeetsworld Yes, is $.post the post that is meant ?
@coymeetsworld that's why I tried the previous example :/
@coymeetsworld Am I heading to the right direction?
Ryan Ledford
@rledford
Nov 18 2016 08:04
@ilkanatabay if your tracks is undefined you can't add a new property. By referencing it with bracket notation it will create the property tracks within the collection with that I'd and assign it the value (new Array() in your case)
Coy Sanders
@coymeetsworld
Nov 18 2016 08:05
yeah @josephinemonica
so this part method=getQuote&key=457653&format=xml&lang=en you want to append to the API url http://api.forismatic.com/api/1.0
with an ampersand between
sorry question mark in between
? will make a query to the API with those parameters
josephinemonica
@josephinemonica
Nov 18 2016 08:07
@coymeetsworld I see
Coy Sanders
@coymeetsworld
Nov 18 2016 08:07
also you could specify the format as json
josephinemonica
@josephinemonica
Nov 18 2016 08:07
@coymeetsworld Can I specify the method , key etc inside the post
Coy Sanders
@coymeetsworld
Nov 18 2016 08:07
and then use the getJSON method you learned to grab the data
that has much simpler syntax than making an ajax call like the .post or .get methods
yes I believe so @josephinemonica
josephinemonica
@josephinemonica
Nov 18 2016 08:08
@coymeetsworld the "method" "key" "format" etc, is that specific to the API, or is that jQuery stuffs?
Coy Sanders
@coymeetsworld
Nov 18 2016 08:08
specific to the API
you could look at this for reference; http://api.jquery.com/jquery.ajax/
josephinemonica
@josephinemonica
Nov 18 2016 08:08
@coymeetsworld So it means if I use other API, the name maybe different e.g. method_2
ilkanatabay
@ilkanatabay
Nov 18 2016 08:09
@rledford i assigned collection[id]["tracks"] to a variable called tracks. i cant understand why i cant add new array as a property with a variable but i can do it with collection[id]["tracks"] notation
Coy Sanders
@coymeetsworld
Nov 18 2016 08:09
but youll see that the ajax methods are a little more complicated than running something like getJSON
Ryan Ledford
@rledford
Nov 18 2016 08:09
@ilkanatabay
Coy Sanders
@coymeetsworld
Nov 18 2016 08:09
yeah @josephinemonica APIs can all be different in some way
if you want to use other ones its best to consult the documentation on it on how to make requests properly
josephinemonica
@josephinemonica
Nov 18 2016 08:10
@coymeetsworld If I want to use jSON, is this correct:
Coy Sanders
@coymeetsworld
Nov 18 2016 08:10
yes
you can even check it by clicking the link
josephinemonica
@josephinemonica
Nov 18 2016 08:11
@coymeetsworld Oh yes, thanks very much, I tried that before but it didn't work cause I missed the question mark
CamperBot
@camperbot
Nov 18 2016 08:11
josephinemonica sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 1549 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
Nov 18 2016 08:11
no problem @josephinemonica, you may need to specify jsonp as the format for cross-origin issues too just FYI
josephinemonica
@josephinemonica
Nov 18 2016 08:11
@coymeetsworld I still can't use the API because of the cross origin thing
@coymeetsworld I see. DO you have any pointers where is the best place to learn more about this http request, cross origin thing?
I have almost zero knowledge to it, I didn't even know the question mark
Ryan Ledford
@rledford
Nov 18 2016 08:14
@ilkanatabay because you're not getting a reference to the collection id tracks, you are getting the value it holds.
Coy Sanders
@coymeetsworld
Nov 18 2016 08:14
@josephinemonica heres something on cross-origin HTTP requests https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
josephinemonica
@josephinemonica
Nov 18 2016 08:15
@coymeetsworld Thank you very much . Very helpful :)
CamperBot
@camperbot
Nov 18 2016 08:15
josephinemonica sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:warning: josephinemonica already gave coymeetsworld points
Coy Sanders
@coymeetsworld
Nov 18 2016 08:15
no problem
Daniel
@scrandy95
Nov 18 2016 08:16
what is wrong with this? var myStr="FirstLine\n\SecondLine\\r ThirdLine";
Reggie
@ReggieSibley
Nov 18 2016 08:16
im about to go crazy
Daniel
@scrandy95
Nov 18 2016 08:16
var myStr="FirstLine\n\SecondLine\\r ThirdLine";
anyone know what is wrong with 144??
c0d0er
@c0d0er
Nov 18 2016 08:18
did anybody use minimax for tic tac toe? need some help on the algo of minimax or tic tac toe AI algo, could anybody help?
ilkanatabay
@ilkanatabay
Nov 18 2016 08:18
@rledford aaaah i see im trying defining undefined as a new array
@rledford thanks a lot!
CamperBot
@camperbot
Nov 18 2016 08:18
ilkanatabay sends brownie points to @rledford :sparkles: :thumbsup: :sparkles:
:cookie: 382 | @rledford |http://www.freecodecamp.com/rledford
Sergey Lukin
@not-a-cylon
Nov 18 2016 08:26
@scrandy95 the backslashes to be included in the string aren't formatted correctly. You need to escape those, too.
Thinh Le
@lqt93
Nov 18 2016 08:34
hi all, i am doing Drop It challenge in Front-end certificate: https://www.freecodecamp.com/challenges/drop-it
And have a question for the test cases:
  • dropElements([0, 1, 0, 1], function(n) {return n === 1;}) should return [1, 0, 1]
  • dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;}) should return [3, 9, 2]
    I think the result in first case should be [1, 1] and the result in second case should be [3, 9], aren't they?
Sergey Lukin
@not-a-cylon
Nov 18 2016 08:35
Doesn't it specify to drop only the first occurence?
or up to the first occurrence.
Ogundele Olumide
@Lumexralph
Nov 18 2016 08:39
@lqt93 it just for you to return the array after the test fails
BasileKoko
@BasileKoko
Nov 18 2016 08:41
Good morning, can someone please look into my code below? this is the Wherefore art though challenge. When I test the failing example I am getting the expected result, not sure I am not able to have 4 green results

function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line

var src_key = (Object.keys(source));
collection.map(function(el){
var e = 0;
while (e < src_key.length){
if (el.hasOwnProperty(src_key[e]) && el[src_key[e]] == source[src_key[e]]) {
return arr.push(el);
}
e++;
}
});

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

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });

//whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });

//whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "c": 2 });

Ogundele Olumide
@Lumexralph
Nov 18 2016 08:42
@lqt93 it require you to check through the array until you get to an element that fails the test, you stop looping, remove that element and return the array , just until you get to the first element that fails the test, that's where the iteration stops....you're not to worry about the rest...you remove the elements before and with the first element that failed the test in the array and return the rest
Markus Kiili
@Masd925
Nov 18 2016 08:47
@BasileKoko You should use forEach instead of map, because you don't use the map return value. You could also use .filter() on collection.
You should only push if the property values match for all the source keys, not just for one key.
BasileKoko
@BasileKoko
Nov 18 2016 08:51
@Masd925 , thanks for the info, I will give it a go
CamperBot
@camperbot
Nov 18 2016 08:51
basilekoko sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2943 | @masd925 |http://www.freecodecamp.com/masd925
Dan Couper
@DanCouper
Nov 18 2016 08:51
@c0d0er what's the situation at which you need to check a non-winning sequence matches against a winning sequence? I'll have a look at the codepen code again, but it suggests the logic is flawed; you shouldn't need to do this
Markus Kiili
@Masd925
Nov 18 2016 08:52
@BasileKoko Using map works but might confuse the reader. Therefore you should use methods for what they are meant for.
Reggie
@ReggieSibley
Nov 18 2016 08:52
whoever can help me solve a problem i'm having on my homework i will send them $50 on paypal
been trying to do it for hours
Chuks Opia
@9jaswag
Nov 18 2016 08:53
hello guys, I'm working on the weather app and I have both the temperature in Celsius and Fahrenheit stored on diff variables. How do I get that of Fahrenheit to show when Celsius is toggled
Thinh Le
@lqt93
Nov 18 2016 08:53
@Lumexralph thanks, i understand it
CamperBot
@camperbot
Nov 18 2016 08:53
lqt93 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 464 | @lumexralph |http://www.freecodecamp.com/lumexralph
c0d0er
@c0d0er
Nov 18 2016 08:54
@DanCouper thanks
CamperBot
@camperbot
Nov 18 2016 08:54
c0d0er sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 357 | @dancouper |http://www.freecodecamp.com/dancouper
Sergey Lukin
@not-a-cylon
Nov 18 2016 08:55
@9jaswag look into click handlers and jQuery's .html() command
Dan Couper
@DanCouper
Nov 18 2016 08:55
Also, if you give each square value in sequence [2,4,8,16,32,64,128,254,
Chuks Opia
@9jaswag
Nov 18 2016 08:56
@not-a-cylon ok.....lemme do that
İnci Qasımova
@inci-august
Nov 18 2016 08:58

Hi. I'm trying to solve "Find the Longest Word in a String" algorithm challenge. Here's my code


function findLongestWord(str) {
  var whitespace = /\s+/g;
  var strArray = str.split(whitespace);
  var wLength = [];

  for(var i = 0; i < strArray.length; i++) {
    wLength.push(strArray[i].length);
  }

  wLength.sort();
  return wLength[wLength.length-1];
}

findLongestWord("The quick brown fox jumped over the lazy dog");

Maybe I'll find a better solution later, but I just want to know what could've gone wrong. It doesn't pass the last test. "findLongestWord("What if we try a super-long word such as otorhinolaryngology") should return 19."

k.vincent
@bobKasbi
Nov 18 2016 09:06
@ReggieSibley no needs man ;-) all can help you here ;-)
Reggie
@ReggieSibley
Nov 18 2016 09:06
noones helped so far
i'm still stuck
k.vincent
@bobKasbi
Nov 18 2016 09:07
You jsut have to make few changes on your script

function filterPricing() {
var myRange = document.getElementById("myRange");
var myRange = myRange.options[myRange.selectedIndex].value;

console.log(myRange);

if (myRange < 500) {
    document.getElementById("firstP").style.visibility = "hidden";

} else if(myRange > 500 && myRange <= 1000) {
    document.getElementById("firstP").style.visibility = "hidden";
    document.getElementById("secondP").style.visibility = "hidden";
    document.getElementById("thirdP").style.visibility = "hidden";
}else if(myRange >= 1000 && myRange <= 2000) {
    document.getElementById("firstP").style.visibility = "hidden";
    document.getElementById("thirdP").style.visibility = "hidden";
    document.getElementById("fourthP").style.visibility = "hidden";
} else {
    document.getElementById("firstP").style.visibility = "visible";
    document.getElementById("secondP").style.visibility = "visible";
    document.getElementById("thirdP").style.visibility = "visible";
    document.getElementById("fourthP").style.visibility = "visible";
}
//return myRange;

}

document.getElementById('myRange').addEventListener('change', filterPricing);

But then fix the missing id in your html markup
firstP doesn't exist
in the html
J Player
@Heyjp
Nov 18 2016 09:09
darkflikk
@darkflikk
Nov 18 2016 09:10
@bobKasbi this looks interesting
J Player
@Heyjp
Nov 18 2016 09:10
they have an example about half way down the page to sort numbers
darkflikk
@darkflikk
Nov 18 2016 09:10
@bobKasbi what is the name of the challenge?
k.vincent
@bobKasbi
Nov 18 2016 09:10
@Heyjp I think our friend needs help regarding his script more than posting him a link ;-)
@darkflikk I kept his script and his html in order to keep it simple for him
darkflikk
@darkflikk
Nov 18 2016 09:11
@bobKasbi you know the name of the challenge?
Sergey Lukin
@not-a-cylon
Nov 18 2016 09:12
@inci-august it's odd, but it appears that wLength.sort(); doesn't actually sort the array. You should look into adding a compare function in there.
k.vincent
@bobKasbi
Nov 18 2016 09:12
@darkflikk he would like t oreorder/sort the div depending on the value of the selectbox
darkflikk
@darkflikk
Nov 18 2016 09:12
@bobKasbi it's not a challenge?
k.vincent
@bobKasbi
Nov 18 2016 09:13
@bobKasbi even the html code should be changed a bit in regards to concept
@darkflikk As I understand it's his home work
darkflikk
@darkflikk
Nov 18 2016 09:13
oh, cause i wanted to see what i can do with switch case there :P
just playing around
J Player
@Heyjp
Nov 18 2016 09:14
@bobKasbi don't see how what I posted wasn't helpful considering the code is 90% fine.
darkflikk
@darkflikk
Nov 18 2016 09:16
@bobKasbi who needs it?
k.vincent
@bobKasbi
Nov 18 2016 09:16
@Heyjp Hm, did you post him something
İnci Qasımova
@inci-august
Nov 18 2016 09:16
@Heyjp @not-a-cylon thanks. I guess I'll try compare function.
CamperBot
@camperbot
Nov 18 2016 09:16
inci-august sends brownie points to @heyjp and @not-a-cylon :sparkles: :thumbsup: :sparkles:
:cookie: 297 | @not-a-cylon |http://www.freecodecamp.com/not-a-cylon
:cookie: 401 | @heyjp |http://www.freecodecamp.com/heyjp
k.vincent
@bobKasbi
Nov 18 2016 09:16
@darkflikk Reggie
Chuks Opia
@9jaswag
Nov 18 2016 09:16
@not-a-cylon I can't seem to find anything useful
darkflikk
@darkflikk
Nov 18 2016 09:17
@ReggieSibley i see
@ReggieSibley what exactly is the problem?
J Player
@Heyjp
Nov 18 2016 09:18
@bobKasbi you said it yourself, no need to be flippant
k.vincent
@bobKasbi
Nov 18 2016 09:21
@Heyjp ??
Reggie
@ReggieSibley
Nov 18 2016 09:22
@darkflikk i can im you?
darkflikk
@darkflikk
Nov 18 2016 09:22
@ReggieSibley yes
Reggie
@ReggieSibley
Nov 18 2016 09:22
i sent
Sergey Lukin
@not-a-cylon
Nov 18 2016 09:26
@9jaswag here's a codepen that might help you out:
http://codepen.io/zooster/pen/vyyPvg
k.vincent
@bobKasbi
Nov 18 2016 09:27
@ReggieSibley I have to go mate... the other guys would surely help
Kush Sharma
@N0M9D
Nov 18 2016 09:41
Hey everyone, i had successfully built the functionality needed for the random quote machine but just to enhance that was tryin to add tweet button as a bonus feature. But the special characters are not recognised in the tweet box after i press the button. I used encodeURIComponent but some characters are still not displaying in the tweet . This is the pen: https://codepen.io/N0M9D/full/mAawAb/
Thayyeb salim
@Thayyebsalim
Nov 18 2016 09:41
i've got absolutely no idea about how to do this
// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
  var val;
  val=id;

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
Kush Sharma
@N0M9D
Nov 18 2016 09:45
@Thayyebsalim use if else conditional logic and build on that
like given in the description for the challenge
Markus Kiili
@Masd925
Nov 18 2016 09:50
@Thayyebsalim Test parameters value and prop and access collection on if blocks. Tracks property needs special love.
Start with testing whether value is an empty string.
Sebastian
@sebshub
Nov 18 2016 09:57
@Thayyebsalim there is a good explanation here https://youtu.be/ZmcKUL1Gm98
Mateusz Kadlubowski
@xeho91
Nov 18 2016 10:13

Anyone who has a good understanding of JS regex here?
I'm struggling with challenge where I kind of have to transform every string to 'snake-case'. Here's my code so far:


function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins

  str = str.replace(/([A-Z]+)/g, ' $1').toLowerCase().replace(/(\s+)/g, '-');
  return str;
}

spinalCase("This Is Spinal Tap");

It almost works, except that if first char in string is uppercase, it adds space before it. How can I avoid that?
Current output is: -this-is-spinal-tap

Thayyeb salim
@Thayyebsalim
Nov 18 2016 10:14
thank you very much @sebshub @Masd925 @N0M9D
CamperBot
@camperbot
Nov 18 2016 10:14
thayyebsalim sends brownie points to @sebshub and @masd925 and @n0m9d :sparkles: :thumbsup: :sparkles:
:cookie: 294 | @n0m9d |http://www.freecodecamp.com/n0m9d
:cookie: 230 | @sebshub |http://www.freecodecamp.com/sebshub
:star2: 2944 | @masd925 |http://www.freecodecamp.com/masd925
Fabio Di Pane
@saylos
Nov 18 2016 10:14
@Thayyebsalim just follow methodically the instructions on the left, you can do that!
Thayyeb salim
@Thayyebsalim
Nov 18 2016 10:15
Ok I'll give it my best @saylos
Fabio Di Pane
@saylos
Nov 18 2016 10:18

@Thayyebsalim you just need to translate what it says and remember that you are using variables, so you don't use

collection.id.prop

but

collection[id][prop]
Blauelf
@Blauelf
Nov 18 2016 10:22
@xeho91 You could try something like /(.)([A-Z])/g, '$1 $2' for the first one (that way it won't trigger at the beginning of the string), and something like /[\s-_]+/g for the second replace (joining all the characters you'd expect to separate words).
Karim
@krimou32
Nov 18 2016 10:23
Hello guys! I reached the seek and destroy challenge and I have no idea how to call the arguments after the array

function destroyer(arr) {
  // Remove all the values
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
how can I access the final 2 and 3 (and other numbers after if there were some)?
Blauelf
@Blauelf
Nov 18 2016 10:24
@krimou32 Use arguments object. It is array-like (has length and numeric properties) and contains all the arguments passed to the function. As arr is the first parameter, it has the same value as arguments[0].
Karim
@krimou32
Nov 18 2016 10:25
@Blauelf ooh ok thank you! when I read the mozilla developers article I thought that "arguments" was just a way to rename any argument called in the function
CamperBot
@camperbot
Nov 18 2016 10:25
krimou32 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 2922 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Nov 18 2016 10:25
@krimou32 Using arguments.length allows you to process arbitrary numbers of arguments :)
Alan
@Murphy47099
Nov 18 2016 10:30
Hi guys, can someone explain to me what is wrong with this? For any first name thats input the console runs the 'else' . "no such contact"
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


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 property";
    }
  }
  else {
    return "No such contact";
  }
}
}
Piotr
@PiotrSzablewski
Nov 18 2016 10:32
@xeho91
anas shaikhany
@hks-adohkd
Nov 18 2016 10:33
@Murphy47099 try == instead of ===
Piotr
@PiotrSzablewski
Nov 18 2016 10:34
@xeho91 you need to change position of toLowerCase()
str = str.toLowerCase().replace(/([A-Z]+)/g, ' $1').replace(/(\s+)/g, '-');
return str;
Alan
@Murphy47099
Nov 18 2016 10:35
@hks-adohkd no dice. I figure both would be applicable
Markus Kiili
@Masd925
Nov 18 2016 10:37
@Murphy47099 Last return in wrong spot.
Your code can return No such contact after checking only one contact.
Thayyeb salim
@Thayyebsalim
Nov 18 2016 10:38
thanks @saylos
CamperBot
@camperbot
Nov 18 2016 10:38
thayyebsalim sends brownie points to @saylos :sparkles: :thumbsup: :sparkles:
:cookie: 248 | @saylos |http://www.freecodecamp.com/saylos
Markus Kiili
@Masd925
Nov 18 2016 10:39
@hks-adohkd There are no good use cases for abstract equality == in JS. If you find one and print and send it to me, I will eat it.
Fabio Di Pane
@saylos
Nov 18 2016 10:40
@Murphy47099 "No such contact" must be outside the for loop, or it will exit the loop
anas shaikhany
@hks-adohkd
Nov 18 2016 10:40
@Masd925 I don't know :( an case sorry
Mateusz Kadlubowski
@xeho91
Nov 18 2016 10:43
@saylos @PiotrSzablewski Thing is it needs to 'add' space between chars firstly, like in this case:
spinalCase("thisIsSpinalTap") should return "this-is-spinal-tap"

@Blauelf Thanks!!!

str = str.replace(/(.)([A-Z])/g, '$1 $2').toLowerCase().replace(/[\s-_]+/g, '-');

It worked perfectly, though I have problems understanding $1 and $2

CamperBot
@camperbot
Nov 18 2016 10:46
xeho91 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 2923 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Nov 18 2016 10:46
@xeho91 The $1 and $2 are replaced by the values from the first and second capture group (the "any character" and "uppercase letter" in this case). There's a whole list of $somethings in the description of replace on MDN.
anas shaikhany
@hks-adohkd
Nov 18 2016 10:48

Hey guys I have solved the "Caesars Cipher" challenge in the "Basic Algorithm Scripting" and my code is:

function rot13(str) { // LBH QVQ VG!
  var trans = {
    "A": "N",
    "B": "O",
    "C": "P",
    "D": "Q",
    "E": "R",
    "F": "S",
    "G": "T",
    "H": "U",
    "I": "V",
    "J": "W",
    "K": "X",
    "L": "Y",
    "M": "Z",
    "N": "A",
    "O": "B",
    "P": "C",
    "Q": "D",
    "R": "E",
    "S": "F",
    "T": "G",
    "U": "H",
    "V": "I",
    "W": "J",
    "X": "K",
    "Y": "L",
    "Z": "M"
  };

  var newStr = "";
  for(var i = 0; i<str.length; i++){
    if(trans.hasOwnProperty(str[i])){
      newStr += trans[str[i]];
    }else{
      newStr += str[i];
    }
  }

  return newStr;
}

however I want to know how can it be solved by the String.charCodeAt() and String.fromCharCode() functions as suggested in the question?

Blauelf
@Blauelf
Nov 18 2016 10:48
@xeho91 The parentheses specify the capture groups.
Mateusz Kadlubowski
@xeho91
Nov 18 2016 10:49
So, the $1 captures any characters from (.) and $2 from ([A-Z])?
Blauelf
@Blauelf
Nov 18 2016 10:49
@hks-adohkd You'd get the charCode, and if it's in the range of A..M, add 13 to it, if in the range of N..Z subtract 13, else don't alter. Then you'd convert those character codes back.
@xeho91 The parentheses do the capture, the $1 are just placeholders that are replaced by the values of those groups.
anas shaikhany
@hks-adohkd
Nov 18 2016 10:51
@Blauelf Yes I know how the algorithm should be but I am too lazy to write the code , if you solved the problem would you please , give the code , and I am not a cheater as I have solved the question as you see
Gabriel
@gabby4hi
Nov 18 2016 10:52
dis is wat i could still do from wat u explained

var count = 0;

function cc(card) {
// Only change code below this line

switch(card){
case 2:
case 3:
case 4:
case 5:
case 6:
count = 5;
result = count + " Bet";
break;
case 2:
case "J":
case 9:
case 2:
case 7:
count = 5 - 4;
result = count + " Bet";
break;

case 2:
case 2:
case 10:
  count = 0;
  result = ++count + " Bet";
  break;

case 3:
case 2:
case "A":
case 10:
case "K":
  count = 0;
  result = --count + " Hold";
  break;

case 7:
case 8:
case 9:
  count = ++count;
  result = count + "  Hold";
  break;

case 10:
case "J":
case "Q":
case "K":
case "A":
  count = -4;
  result =--count + " Hold";
  break;

}

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

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

anas shaikhany
@hks-adohkd
Nov 18 2016 10:52
@Blauelf I just need to know how it can be solved using the suggested functions
Mateusz Kadlubowski
@xeho91
Nov 18 2016 10:54
@Blauelf so if $1 are just placeholders, why it just adds white spaces instead of "$1" between chars? I'm a bit confused and reading the MDN documentation doesn't make it any more clear to me :(
Blauelf
@Blauelf
Nov 18 2016 10:54
@xeho91 I used that for pig latin, something like
  return ~"aiueo".indexOf(str[0]) ? str + "way" : str.replace(/([^aiueo]+)(.*)/, "$2$1ay");
Mateusz Kadlubowski
@xeho91
Nov 18 2016 10:55
@Blauelf or the space is added because there's a space between $1<this is a white space>$2?
Blauelf
@Blauelf
Nov 18 2016 10:56
@xeho91 It takes the space from the string. It's replacing by the string, just replacing those placeholders first, the other parts are taken as they are.