These are chat archives for FreeCodeCamp/HelpJavaScript

26th
Mar 2017
__SharifTarver__
@Sharifdesigns22
Mar 26 2017 00:00
what am I missing?
obscuredetour
@obscuredetour
Mar 26 2017 00:00
if (1) ?
Marko
@vuckookv3
Mar 26 2017 00:00
if (1) is always equals to true..
put if(strokes == 1)
Alimi Kehinde Morufudeen
@marusoft
Mar 26 2017 00:00
@rayjrm introducong else statement
Marko
@vuckookv3
Mar 26 2017 00:01
@marusoft
devashreeganesha108gmailcom
@devashreeganesha108gmailcom
Mar 26 2017 00:01

function largestOfFour(arr) {
var arrayWithLargestNumber = arr[0];
var larger;
for(i = 1; i < arr.length; i++){
var subArray = arr[i];
for(j = 0; j < subArray.length; j++){
for(k = 0; arrayWithLargestNumber.length; k++){
if(subArray[j] > arrayWithLargestNumber[k]){
larger = true;
}
else{
larger = false;
}
}
if(larger){
arrayWithLargestNumber = arr[i];
}
}
}
return arrayWithLargestNumber;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

Marko
@vuckookv3
Mar 26 2017 00:01
```
if (val < 5 ) {
result = "Bigger than 5";
}
else {
result = "5 or Smaller";
}
```
devashreeganesha108gmailcom
@devashreeganesha108gmailcom
Mar 26 2017 00:01
can someone help me figure out as to why this is not working?
Keon Samuel
@keonsam
Mar 26 2017 00:02
why is my argument array not working?
var args = Array.prototype.slice.call(arguments);
silver537
@silver537
Mar 26 2017 00:02
@DanCouper only cause i hate for loops :3
sumAll= (a,n= Math.min(...a))=> n===Math.max(...a)? n: n+ sumAll(a, n+1)
Zandrew S
@popezandy
Mar 26 2017 00:02
var Car = function(wheels, seats, engines) {
  //Change this constructor
  this.wheels = 4;
  this.seats = 5;
  this.engines = 1;
};

//Try it out here
var myCar = new Car(3, 1, 2);
Ray Martinez
@rayjrm
Mar 26 2017 00:03
@marusoft If statements condition needs only to test if val is greater than 5
Mayur
@mayurpande
Mar 26 2017 00:03
hey all, can someone explain to me what are base pairs?
Marko
@vuckookv3
Mar 26 2017 00:03
@popezandy
```
var Car = function(wheels, seats, engines) {
  //Change this constructor
  this.wheels = wheels;
  this.seats = seats;
  this.engines = engines;
};

//Try it out here
var myCar = new Car(3, 1, 2);
```
Zandrew S
@popezandy
Mar 26 2017 00:03
right that makes more sense
shiz I need to pay attention in my object oriented programming course
Ray Martinez
@rayjrm
Mar 26 2017 00:04
@marusoft Did that work out?
silver537
@silver537
Mar 26 2017 00:05
@rayjrm but yea i only suggested recursion cause you asked. there are many ways to code.
@mayurpande are you doing the DNA challenge?
gottingerfrank
@drpacket
Mar 26 2017 00:06
function lookUpProfile(firstName, prop){
var i = 0;
while (i < contacts.length) {
  if (firstName === contacts[i]["firstName"] && contacts[i][prop]) {
    return contacts[i][prop];
  } else if (firstName !== contacts[i]["firstName"] && (!contacts[i][prop])) {
    i += 1
    continue;
  } else if (firstName !== contacts[i]["firstName"]) {
    return "No such contact";
  } else if (!contacts[i][prop]) {
    return "No such property";
  } 
  }
}

// Change these values to test your function

console.log(lookUpProfile("Akira", "number")); // works
console.log(lookUpProfile("Akira", "likes"));  // works
console.log(lookUpProfile("Harry", "number"));  // doesn´t work

// Any ideas what`s wrong with this function? (doesnt seem to increment)
—> this function should loop through an array of objects. (challenge #213 „Profile Lookup“)
Any ideas what I´m missing here?
Alimi Kehinde Morufudeen
@marusoft
Mar 26 2017 00:06
@rayjrm no
michaelpare07
@michaelpare07
Mar 26 2017 00:06
Can I get some help for repeating a string a certain number of times
Ray Martinez
@rayjrm
Mar 26 2017 00:06
@marusoft paste your code again so i can see what you changed, please.
Mayur
@mayurpande
Mar 26 2017 00:06
@silver537 yes that's the one, not so clued up about chemistry!
silver537
@silver537
Mar 26 2017 00:07
@mayurpande they show you what the pairings are.
AT TA CG GC those are the pairings
michaelpare07
@michaelpare07
Mar 26 2017 00:07
For example, if I have a string "abc" and I want to repeat it 3 times so that it reads "abcabcabc", any suggestions?
Ray Martinez
@rayjrm
Mar 26 2017 00:07
@silver537 No, i appreciate it. I guess I was just looking for someone to point out any redundancy, cause I felt like there definitely is some
Moisés Man
@moigithub
Mar 26 2017 00:07
loop + string concatenation @michaelpare07
Anne L
@mathisme
Mar 26 2017 00:08
Jinx, was just going to say that
Declare a variable, var str = ""; create a for loop, in the loop str+=yourstring
silver537
@silver537
Mar 26 2017 00:09
@rayjrm well in my opinion, if statements are redundant :P i onlt use them if i reeeeeeeally need them. but other than that, you're fine.
obscuredetour
@obscuredetour
Mar 26 2017 00:09
@rayjrm
I finally understand what they meant by recursion now. I thought, like you, that a loop was required for that.
function factorialize(num) {

  if (num === 0)

    return 1;

  return num * factorialize(num-1);

}
silver537
@silver537
Mar 26 2017 00:10
the function calling itself IS the loop/
Ray Martinez
@rayjrm
Mar 26 2017 00:10
@silver537 Its interesting, I though learning syntax was gonna be hard, but the real challenge is the strategy, and efficiency
Mayur
@mayurpande
Mar 26 2017 00:10
@silver537 but then in one of the conditions it says "TTGAG" should return [["T","A"],["T","A"],["G","C"],["A","T"],["G","C"]] so why does TT return the first ["T","A"]
obscuredetour
@obscuredetour
Mar 26 2017 00:11
yeah exactly @silver537 I was totally not getting that for like that last hour! yeeesh
Anne L
@mathisme
Mar 26 2017 00:11
Each T is paired with A
Ray Martinez
@rayjrm
Mar 26 2017 00:11
@obscuredetour Haha, wow, it's so simple! :)
Anne L
@mathisme
Mar 26 2017 00:12
G with C and vice versa
Mayur
@mayurpande
Mar 26 2017 00:12
@mathisme ah ok, cool thanks will give it a go
CamperBot
@camperbot
Mar 26 2017 00:12
mayurpande sends brownie points to @mathisme :sparkles: :thumbsup: :sparkles:
:cookie: 281 | @mathisme |http://www.freecodecamp.com/mathisme
silver537
@silver537
Mar 26 2017 00:12
@mayurpande the bases cant be paired with itself
Mayur
@mayurpande
Mar 26 2017 00:13
cool thanks @silver537
CamperBot
@camperbot
Mar 26 2017 00:13
mayurpande sends brownie points to @silver537 :sparkles: :thumbsup: :sparkles:
:cookie: 893 | @silver537 |http://www.freecodecamp.com/silver537
silver537
@silver537
Mar 26 2017 00:13
well not cant perse, more like don't
Anne L
@mathisme
Mar 26 2017 00:13
No problem :)
silver537
@silver537
Mar 26 2017 00:14
@rayjrm its beautiful when you become the master of the computer once in a while. and not the other way around. :P
obscuredetour
@obscuredetour
Mar 26 2017 00:14
Indeed. I still can't believe it was so simple.
silver537
@silver537
Mar 26 2017 00:15
@obscuredetour it becomes harder.
try to reverse a string with recursion
Ray Martinez
@rayjrm
Mar 26 2017 00:15
lol
Manish Giri
@Manish-Giri
Mar 26 2017 00:15
what's the difference between "non equality" and "inequality"
silver537
@silver537
Mar 26 2017 00:16
@Manish-Giri you tell me
Alimi Kehinde Morufudeen
@marusoft
Mar 26 2017 00:16

@rayjrm
function testElse(val) {
var result = "";
// Only change code below this line

if (val > 5) {
result = "Bigger than 5";
}

if (val <= 5) {
result = "5 or Smaller";
}

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

// Change this value to test
testElse(4);

obscuredetour
@obscuredetour
Mar 26 2017 00:16
lol it already is hard :smile:
silver537
@silver537
Mar 26 2017 00:17
i wish i can talk to computers like that kid in heroes
Ray Martinez
@rayjrm
Mar 26 2017 00:17
@marusoft You only need one if statement, the second if statement should instead be an else. The else needs no condition
Manish Giri
@Manish-Giri
Mar 26 2017 00:17
@silver537 idk, which is why I asked lol
silver537
@silver537
Mar 26 2017 00:18
they mean the same no?
obscuredetour
@obscuredetour
Mar 26 2017 00:18
@marusoft if val is initially bigger than 5, what 'else' can it be besides smaller?
silver537
@silver537
Mar 26 2017 00:19
@obscuredetour '''
CamperBot
@camperbot
Mar 26 2017 00:19
:bulb: to format code use backticks! ``` more info
Ray Martinez
@rayjrm
Mar 26 2017 00:19
See, else needs no other condition, because if its not greater than 5, it MUST be equal to or less than
else {
    result = "5 or Smaller";
  }
@marusoft
Manish Giri
@Manish-Giri
Mar 26 2017 00:19
@silver537 I thought so too
but this book I was reading
said they're not the same
Alimi Kehinde Morufudeen
@marusoft
Mar 26 2017 00:20
@rayjrm ok thank
CamperBot
@camperbot
Mar 26 2017 00:20
marusoft sends brownie points to @rayjrm :sparkles: :thumbsup: :sparkles:
:cookie: 10 | @rayjrm |http://www.freecodecamp.com/rayjrm
silver537
@silver537
Mar 26 2017 00:20
@Manish-Giri lmao i thought the question was sarcasm. xD
Manish Giri
@Manish-Giri
Mar 26 2017 00:20

@silver537

There are four equality operators: ==, ===, !=, and !==. The ! forms are of course the symmetric "not equal" versions of their counterparts; non-equality should not be confused with inequality.

lol no it was real
Ray Martinez
@rayjrm
Mar 26 2017 00:21
:)
obscuredetour
@obscuredetour
Mar 26 2017 00:21
haha
oh I didn't know about single line code
Alimi Kehinde Morufudeen
@marusoft
Mar 26 2017 00:22
@rayjrm pls how do i combine that if statement of >5 and <=5
Keon Samuel
@keonsam
Mar 26 2017 00:22
I quit man
silver537
@silver537
Mar 26 2017 00:22
@Manish-Giri got the answer! i forgot that inequality deals with > < >= <=
Manish Giri
@Manish-Giri
Mar 26 2017 00:22
oooh
makes sense
altho feels weird
@silver537 thanks
CamperBot
@camperbot
Mar 26 2017 00:23
manish-giri sends brownie points to @silver537 :sparkles: :thumbsup: :sparkles:
:cookie: 894 | @silver537 |http://www.freecodecamp.com/silver537
silver537
@silver537
Mar 26 2017 00:23
lol yea
and non-equality references to the ! in the equalities
!== and so forth
so we got equalities, non-equalities, and inequalities
lol wtf man
Keon Samuel
@keonsam
Mar 26 2017 00:24
programming is a bitch lol
silver537
@silver537
Mar 26 2017 00:24
no that's just logic
basic logic
we tend to forget the basics
Ray Martinez
@rayjrm
Mar 26 2017 00:25
@marusoft
if () {

} else {

}
@marusoft Sorry, but I don't want to justgive you the solution. Forgive me if I'm not explaining it clearly. :/
silver537
@silver537
Mar 26 2017 00:27
na that's how it's done
those who demand answers, never learn.
then miss out on a great opportunity cause they quit.
Ray Martinez
@rayjrm
Mar 26 2017 00:28
Learning hurts :(
Alimi Kehinde Morufudeen
@marusoft
Mar 26 2017 00:29

@rayjrm function testElse(val) {
var result = "";
// Only change code below this line

if (val > 5 && val <= 5) {
result = "Bigger than 5";
}

else {
result = "5 or Smaller";
}

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

// Change this value to test
testElse(4

silver537
@silver537
Mar 26 2017 00:30
@marusoft what's this? val <= 5
Ray Martinez
@rayjrm
Mar 26 2017 00:30
@marusoft Cool, your else statement is correct, but your If statement only needs one condition. It needs only to test if val is > than 5
Alimi Kehinde Morufudeen
@marusoft
Mar 26 2017 00:30
@rayjrm ok
@rayjrm bravvvvo it works\
Ray Martinez
@rayjrm
Mar 26 2017 00:32
Neato!
silver537
@silver537
Mar 26 2017 00:35
i just realized i used recursion for the repeat a string challenge. -.-
i have the habit of redoing the challenges in a different way, and leaving the code there.
Ray Martinez
@rayjrm
Mar 26 2017 00:36
:)
Lovely
silver537
@silver537
Mar 26 2017 00:39
third atempt
Ray Martinez
@rayjrm
Mar 26 2017 00:40
wow lol
silver537
@silver537
Mar 26 2017 00:40
and then finally the fourth one which was the first one i showed
@rayjrm do you see the growth of understanding?
the more you code the more you find yourself repeating yourself
and then you realize, ECMAScript had built in methods that do all of it for you.
Manish Giri
@Manish-Giri
Mar 26 2017 00:42
@silver537 something like this?
function repeat(str, num) {
  if(num < 1) {
    return str;
  }
  else {
    return str + repeat(str, num-2);
  }
}
silver537
@silver537
Mar 26 2017 00:43
well... yea
i used ternary though
Manish Giri
@Manish-Giri
Mar 26 2017 00:43
come to think of it
silver537
@silver537
Mar 26 2017 00:43
i despise if statements :P
Manish Giri
@Manish-Giri
Mar 26 2017 00:44
this might be one possible solution to String.prototype.repeat()
silver537
@silver537
Mar 26 2017 00:44
it is
just without the recursion, of course
Fher Gomez
@fhergomez
Mar 26 2017 00:46
could somebody help please. I’m trying to write the following code as jQuery
var html = '<div class="media"><div class="media-left"><img src="' + imgUrl + '" class="media-object" style="width:60px"></div><div class="media-body"><h4 class="media-heading">' + '<a href="' + userUrl + '" target="_blank">' + user + '</a>' + '</h4><p>' + statusblurb + '</p></div></div>’

document.getElementById(‘#output').innerHTML += "<hr>" + html
Jan Shah
@JanShah
Mar 26 2017 00:47
$('#output').append() ?
silver537
@silver537
Mar 26 2017 00:48
jquery would be more confusing
cause it's all about traversing the DOM
Fher Gomez
@fhergomez
Mar 26 2017 00:51
I’m wondering if I should iterate
Zulfikar
@zbandhan
Mar 26 2017 00:51
Please Help to Complete "Word Blanks" Game.
silver537
@silver537
Mar 26 2017 00:51
it's not a game
Manish Giri
@Manish-Giri
Mar 26 2017 00:51
lol
Ray Martinez
@rayjrm
Mar 26 2017 00:51
lowers sunglasses
silver537
@silver537
Mar 26 2017 00:51
@fhergomez you would have better luck in the https://gitter.im/FreeCodeCamp/Help room
Zulfikar
@zbandhan
Mar 26 2017 00:52

```function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line

// Your code above this line
return result;
}```

silver537
@silver537
Mar 26 2017 00:53
@zbandhan so whats the problem
Zulfikar
@zbandhan
Mar 26 2017 00:53
what is non-word to be separeted
silver537
@silver537
Mar 26 2017 00:53
i know what the challenge is about, but what are YOU have trouble with
Jan Shah
@JanShah
Mar 26 2017 00:54
@fhergomez
does this help?
var newDiv = document.createElement("div");
newDiv.classList.add('className');
newDiv.setAttribute('id','idName')
Zulfikar
@zbandhan
Mar 26 2017 00:55
I cannot understand about non-word character. what does it mean by
Manish Giri
@Manish-Giri
Mar 26 2017 00:55
@zbandhan like , or -
Jan Shah
@JanShah
Mar 26 2017 00:55
@zbandhan anything that is not a word, like a space
Ray Martinez
@rayjrm
Mar 26 2017 00:55
" ", ' '
Fher Gomez
@fhergomez
Mar 26 2017 00:55
@CentropyIT I’ll try it
silver537
@silver537
Mar 26 2017 00:55
@CentropyIT he wants to convert that code to jquery
Zulfikar
@zbandhan
Mar 26 2017 00:56
Oh got it
Manish Giri
@Manish-Giri
Mar 26 2017 00:57
@fhergomez there are a couple of ways to do that
  1. get the current html with .html() - append to it and set it with .html(...)
  2. use .append()
Jan Shah
@JanShah
Mar 26 2017 00:57
@silver537 I inferred slightly differently.
silver537
@silver537
Mar 26 2017 00:58
@CentropyIT no worries. it was still good code :P
Fher Gomez
@fhergomez
Mar 26 2017 00:59
@Manish-Giri I’m not sure I understand
Jan Shah
@JanShah
Mar 26 2017 01:00
it's good for small bits but I used it to create the grid and buttons for the tic tac toe game and it got really confusing so I rewrote into something even more confusing..
and then gave up and messed with it even more.. it's unreadable but works..

@fhergomez another thing I did use was :

$('#cover').append( function() {} )

to generate the html.. there :)

Fher Gomez
@fhergomez
Mar 26 2017 01:03
@CentropyIT let me give it a try
Manish Giri
@Manish-Giri
Mar 26 2017 01:03
Gulsvi
@gulsvi
Mar 26 2017 01:07
@fhergomez I'd translate your vanillaJS to jQuery like this:
$('#output').append(
  `<hr>
   <div class="media">
     <div class="media-left">
       <img src="${imgUrl}" class="media-object" style="width:60px">
     </div>
     <div class="media-body">
       <h4 class="media-heading"><a href="${userUrl}" target="_blank">${user}</a></h4>
       <p>${statusblurb}</p>
     </div>
   </div>`
);
Fabusuyi David Oluwasegun
@dav4thevid
Mar 26 2017 01:08
hello everyone.......my code
```

function chainToSwitch(val) {
  var answer = "";
  // Only change code below this line

  switch (val) {case "bob":answer ="Marley";break; 
    case "42":answer ="The Answer";break;
    case "1":answer = "There is no #1";break;
    case "99":answer = "Missed me by this much!";break;
    case "7": answer = "Ate Nine";


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

// Change this value to test
chainToSwitch(7);
is not passing
Manish Giri
@Manish-Giri
Mar 26 2017 01:09
should the numbers be in quotes?
"42"?
etc
@dav4thevid
Fabusuyi David Oluwasegun
@dav4thevid
Mar 26 2017 01:10
yes @Manish-Giri
Ray Martinez
@rayjrm
Mar 26 2017 01:11
you're giving a numerical argument, but checking for a string
Fher Gomez
@fhergomez
Mar 26 2017 01:11
@SkyCoder01 append worked….thank you!!!
Fabusuyi David Oluwasegun
@dav4thevid
Mar 26 2017 01:11

function chainToSwitch(val) {
  var answer = "";
  // Only change code below this line

  switch (val) {case "bob":answer ="Marley";break; 
    case 42:answer ="The Answer";break;
    case 1:answer = "There is no #1";break;
    case 99:answer = "Missed me by this much!";break;
    case 7: answer = "Ate Nine";


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

// Change this value to test
chainToSwitch(7);
Fher Gomez
@fhergomez
Mar 26 2017 01:11
@Manish-Giri Thank you for your help!
CamperBot
@camperbot
Mar 26 2017 01:11
fhergomez sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 4923 | @manish-giri |http://www.freecodecamp.com/manish-giri
Fabusuyi David Oluwasegun
@dav4thevid
Mar 26 2017 01:11
removed the quotes still not passing
Fher Gomez
@fhergomez
Mar 26 2017 01:12
@SkyCoder01 Thank you!
CamperBot
@camperbot
Mar 26 2017 01:12
fhergomez sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
:cookie: 683 | @skycoder01 |http://www.freecodecamp.com/skycoder01
Gulsvi
@gulsvi
Mar 26 2017 01:12
@fhergomez Happy to help :) The ` backticks help too - no need for a +, just wrap your variables in curly braces with a dollar sign.
Jan Shah
@JanShah
Mar 26 2017 01:13
missing } at the end of the switch statements
@dav4thevid
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:14
Hey how does one complete the "stand in line" challenge?
Ray Martinez
@rayjrm
Mar 26 2017 01:15
With fervor!
Fabusuyi David Oluwasegun
@dav4thevid
Mar 26 2017 01:15
@CentropyIT @Manish-Giri thanks guys
CamperBot
@camperbot
Mar 26 2017 01:15
:cookie: 340 | @centropyit |http://www.freecodecamp.com/centropyit
:star2: 4924 | @manish-giri |http://www.freecodecamp.com/manish-giri
dav4thevid sends brownie points to @centropyit and @manish-giri :sparkles: :thumbsup: :sparkles:
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:16
Anybody know how to solve the challenge?
Fabusuyi David Oluwasegun
@dav4thevid
Mar 26 2017 01:16
its passed........value shouldnt be in "" en forgot }
Ray Martinez
@rayjrm
Mar 26 2017 01:16
@TJTheRandomCoder Can you share your code
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:16
I haven't done anything because I cannot think of how to approach this @rayjrm

function nextInLine(arr, item) {
// Your code here

return item; // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

this is the base template
Manish Giri
@Manish-Giri
Mar 26 2017 01:17
@TJTheRandomCoder there are two steps in that challenge -
  1. add the number item to the end of the array arr
  2. remove the first element from the array arr and return it.
    The two functions - .push() and .shift() would be helfpul.
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:18
can you explain the first one?
"to the end of the array arr"
silver537
@silver537
Mar 26 2017 01:18
@TJTheRandomCoder and
3 refer to this challenge Return a Value from a Function with Return
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:19
Funny enough I have that open
silver537
@silver537
Mar 26 2017 01:19
@TJTheRandomCoder yea that will help number on 2
there are two steps in that challenge -
  1. add the number item to the end of the array arr
  2. remove the first element from the array arr and return it.
    The two functions - .push() and .shift() would be helfpul.
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:20
I don't understand step 1 at all. Can you explain it? @silver537
silver537
@silver537
Mar 26 2017 01:21

thats where this comes in

The two functions - .push() and .shift() would be helfpul.

Manish Giri
@Manish-Giri
Mar 26 2017 01:21
given an array [1, 2, 3] how would you add the number 4 to the end of the array?
@TJTheRandomCoder
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:23
you would um
Ray Martinez
@rayjrm
Mar 26 2017 01:23
@TJTheRandomCoder You will need to push() item into arr
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:23
variablename.push("4")?
also forgot the ;
Manish Giri
@Manish-Giri
Mar 26 2017 01:23
yeah
but .push(4)
not "4"
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:24
oh okay
Manish Giri
@Manish-Giri
Mar 26 2017 01:24
that's step 1, explained..
Jan Shah
@JanShah
Mar 26 2017 01:24
console.log ftw
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:25
I'm still managing to not comprehend this fml
Ray Martinez
@rayjrm
Mar 26 2017 01:26
@TJTheRandomCoder Do you remember how push() and shift() work?
silver537
@silver537
Mar 26 2017 01:26
lol
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:26
push adds to the end of an array while shift moves?
Ray Martinez
@rayjrm
Mar 26 2017 01:27
shift removes from the beginning of an array
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:27
so they're absolute opposites where push adds to the end
and shift removes from the front
Ray Martinez
@rayjrm
Mar 26 2017 01:27
not quite
silver537
@silver537
Mar 26 2017 01:27
no
Lee
@eightlimbs
Mar 26 2017 01:27
hey guys
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:27
elaborate please?
silver537
@silver537
Mar 26 2017 01:27
there are four methods
Manish Giri
@Manish-Giri
Mar 26 2017 01:27
did you read the MDN docs?
@TJTheRandomCoder
Lee
@eightlimbs
Mar 26 2017 01:27
question about javascript... i am on the second challenge
silver537
@silver537
Mar 26 2017 01:28
shift unshift push pop
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:28
I don't think so lol
Manish Giri
@Manish-Giri
Mar 26 2017 01:28
then do so
Ray Martinez
@rayjrm
Mar 26 2017 01:28
the opposite of shift would be unshift, as they both interact with the first item in an array, pop is the opposite of push as it also interacts only with the last item in an array @TJTheRandomCoder
Lee
@eightlimbs
Mar 26 2017 01:28
the assignment is to:
  1. assign the value of 7 to variable a
  2. assign the contents of a to variable b

i've got

var a = 7;

I don't know how to do #2... don't understand
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:29
@eightlimbs you would set the same format for the variable b
and @rayjrm so shift and unshift are like a pair and pop and push are a pair?
silver537
@silver537
Mar 26 2017 01:29
@eightlimbs if i give you a what am i really giving you?
Ray Martinez
@rayjrm
Mar 26 2017 01:29
yep!
@TJTheRandomCoder
Lee
@eightlimbs
Mar 26 2017 01:29
@silver537 7
silver537
@silver537
Mar 26 2017 01:30
ok... you are b
understand?
Lee
@eightlimbs
Mar 26 2017 01:30
hmm...
no
it says A should be assigned to B with =
silver537
@silver537
Mar 26 2017 01:30
you're b, and i gave you a
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:30
@rayjrm So I get how it works but in this case how do I use it? Like what variable would i assign whatever it is to?
Lee
@eightlimbs
Mar 26 2017 01:31
I'm b, and you gave me 7 (a)
silver537
@silver537
Mar 26 2017 01:31
exactly
Lee
@eightlimbs
Mar 26 2017 01:31
var b = var a ?
silver537
@silver537
Mar 26 2017 01:31
so now b= ....
a already has var
Jan Shah
@JanShah
Mar 26 2017 01:31
@eightlimbs you can assign a variable to another variable, just don't redeclare it
Lee
@eightlimbs
Mar 26 2017 01:31
b = 7
silver537
@silver537
Mar 26 2017 01:31
nooooo
b = a
Lee
@eightlimbs
Mar 26 2017 01:32
lol
silver537
@silver537
Mar 26 2017 01:32
cmon man
you had it right the first time
lol
Lee
@eightlimbs
Mar 26 2017 01:32
ok
a = 8
a = b **
silver537
@silver537
Mar 26 2017 01:32
-.-
you did it again man
Lee
@eightlimbs
Mar 26 2017 01:32

so ...

var a = ??

var a = 7
silver537
@silver537
Mar 26 2017 01:32
var b = var a ?
Ray Martinez
@rayjrm
Mar 26 2017 01:32
@TJTheRandomCoder
yourArray.push(yourItem);
Lee
@eightlimbs
Mar 26 2017 01:33
wait
var a = b ??
silver537
@silver537
Mar 26 2017 01:33
-.-
almost there
Lee
@eightlimbs
Mar 26 2017 01:33
var b = a ??
Jan Shah
@JanShah
Mar 26 2017 01:33
@eightlimbs yes
silver537
@silver537
Mar 26 2017 01:33
@eightlimbs DING DING DING!!!!!!
Lee
@eightlimbs
Mar 26 2017 01:33
yayyyy
lol
thank you @silver537 @CentropyIT !! :D
CamperBot
@camperbot
Mar 26 2017 01:34
eightlimbs sends brownie points to @silver537 and @centropyit :sparkles: :thumbsup: :sparkles:
:cookie: 895 | @silver537 |http://www.freecodecamp.com/silver537
:cookie: 341 | @centropyit |http://www.freecodecamp.com/centropyit
silver537
@silver537
Mar 26 2017 01:34
but do you understand WHY that works?!?!? or how it can be utilized?
logically?
Lee
@eightlimbs
Mar 26 2017 01:34
let me try to explain...
silver537
@silver537
Mar 26 2017 01:34
shoot
Lee
@eightlimbs
Mar 26 2017 01:34
the variable a is assigned 7
but 7 could be changed to anything
silver537
@silver537
Mar 26 2017 01:35
nice
Lee
@eightlimbs
Mar 26 2017 01:35
we want var b to equal var a
Tejinder Mann
@TJTheRandomCoder
Mar 26 2017 01:35
@rayjrm I'm so confused damn it
Lee
@eightlimbs
Mar 26 2017 01:35
errr
Ray Martinez
@rayjrm
Mar 26 2017 01:35
Breathe :)
Lee
@eightlimbs
Mar 26 2017 01:35
we want var b to = whatever a is
silver537
@silver537
Mar 26 2017 01:35
yes
Lee
@eightlimbs
Mar 26 2017 01:36
i'm trying to this of how this could relate to what i've learned so far with CSS/HTML
think*
...
Jan Shah
@JanShah
Mar 26 2017 01:36
@eightlimbs it'll be really good when you get there
Lee
@eightlimbs
Mar 26 2017 01:37
if A = "font-color: red;"
silver537
@silver537
Mar 26 2017 01:37
essentiallyit creates a copy. so maybe you want many different outcomes of the same source? but you don't want to change the source. only the methods used.
however, the methods used can change the source. so we duplicate the source for the method to use instead.
Lee
@eightlimbs
Mar 26 2017 01:38
what is an instance where you would want many different outcomes of the same source?
silver537
@silver537
Mar 26 2017 01:39
idk.
maybe your project gets too large and there's confusion everywhere?
might overwrite the initial value
Lee
@eightlimbs
Mar 26 2017 01:40
ok
that doesn't make much sense to me yet
but maybe it will as i move on
silver537
@silver537
Mar 26 2017 01:40
yea you'll get there.
Lee
@eightlimbs
Mar 26 2017 01:40
@silver537 , thank you for your help. do you have a website?
CamperBot
@camperbot
Mar 26 2017 01:40
eightlimbs sends brownie points to @silver537 :sparkles: :thumbsup: :sparkles:
:warning: eightlimbs already gave silver537 points
silver537
@silver537
Mar 26 2017 01:41
naa
i just code for fun :3
Lee
@eightlimbs
Mar 26 2017 01:41
cool :)
silver537
@silver537
Mar 26 2017 01:42
here's one example i just thought of. var b = a * a
Jan Shah
@JanShah
Mar 26 2017 01:45
@silver537 have you ever been on codewars.com?
silver537
@silver537
Mar 26 2017 01:45
yea have you ever been on coodefights?
its more challenging .
imo
of course
Manish Giri
@Manish-Giri
Mar 26 2017 01:46
example of?
Jan Shah
@JanShah
Mar 26 2017 01:48
I originally only went on codewars because a certain criteria help my eligibility for a subsidised (read free) bootcamp but I didn't realise how much more I could learn from it, it's awesome! I check out codefights
silver537
@silver537
Mar 26 2017 01:50

You have an undirected weighted graph represented as an adjacency matrix. You are allowed to add no more than addLimit edges of the given weight to the graph. An edge can be added between two nodes if there's no edge between them yet. Here's your task:

Find the shortest path from start to finish, adding additional edges if necessary;
Among all possible shortest paths, calculate the number of such paths that can be constructed by adding the minimum possible number of additional edges.
Return the answer as an array in the format [a, b], where a is the weight of the shortest path and b is the number of shortest paths built using the minimum possible number of additional edges. It is guaranteed that at least one path always exists.

For start = 1, finish = 4, weight = 4, edgeLimit = 1 and

graph = [[0,2,2,0],
         [2,0,0,2],
         [2,0,0,2],
         [0,2,2,0]]

the output should be
shortestPathWithManyEdges(start, finish, weight, edgeLimit) = [4, 2].

these guys make you think
silver537
@silver537
Mar 26 2017 01:58
and this challenge is supposed to be easy
jermikah
@jermikah
Mar 26 2017 02:27
Is this code wrong? myArray.unshift("Paul", 35);
silver537
@silver537
Mar 26 2017 02:28
no why?
jermikah
@jermikah
Mar 26 2017 02:28
The result keeps coming up as myArray = ["Paul",35,["dog",3]]
silver537
@silver537
Mar 26 2017 02:29
because that's what you're unshifting
jermikah
@jermikah
Mar 26 2017 02:30
Its saying the code should have two brackets [[ in the front of Paul not one,I am only getting one
juni
@junipberry
Mar 26 2017 02:30
can I get some help on card counting?
Been stuck on that one for awhile
silver537
@silver537
Mar 26 2017 02:30
@jermikah then add those brackets.
what do brackets represent?
@junipberry post code
jermikah
@jermikah
Mar 26 2017 02:31
I tried, its not letting me continue -_-
silver537
@silver537
Mar 26 2017 02:32
@jermikah what do brackets represent?
juni
@junipberry
Mar 26 2017 02:33

@silver537 , Here is my code..it’s got quite a few errors in it and I’m somewhat overwhelmed on how to approach fixing it.
```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;
result= 1, 2, 3, 4, 5 or 6;
break;

case 10:
case J:
case Q:
case K:
case A:
  count -=1;
 result= 10, J, Q, K, or A;
  break;

default;
  count; 

}

if (1, 2, 3, 4, 5 or 6) {
return (count "Bet");
}
else {
return (count "Hold");
}
```

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;
    result= 1, 2, 3, 4, 5 or 6;
      break;

    case 10:
    case J:
    case Q:
    case K:
    case A:
      count -=1;
     result= 10, J, Q, K, or A;
      break;

    default;
      count; 
  }

  if (1, 2, 3, 4, 5 or 6) {
      return (count "Bet");
  }
  else {
      return (count "Hold");
  }
jermikah
@jermikah
Mar 26 2017 02:34
I'm guessing stacking
just started coding a few days ago
silver537
@silver537
Mar 26 2017 02:35
na its an array
so unshift the same thing just inside brackets
unshift([whatever, here])
jermikah
@jermikah
Mar 26 2017 02:37
WHAT!!!!! ARGH!!!! That simple. Thanks.
Ken Haduch
@khaduch
Mar 26 2017 02:40
@junipberry - well, you are somewhat on the right track. One thing - your lines result = 1,2,3,4,5 or 6; are erroneous and unnecessary to do anything like that. Basically keeping the count variable value is what you need. Then the "cards" like J, Q, K, A have to be represented by string values: "J", "Q", etc. Lastly, you test the value of count and just translate the instructions that they give into code, it is basically checking if count is greater than 0, or whatever they say, and return count + " Bet" or count + " Hold" - note the space in the string part.
Joseph
@revisualize
Mar 26 2017 02:40

How to write an if conditional statements with OR and AND operators:
I am seeing a large number of people writing if conditions using OR and AND operators incorrectly.
Here is an example of what I'm seeing:

if (param1 == "a" || "c" || "e") { // incorrect
   var output = "Odd lowercase alpha character"; 
}

What I think people think is that it will compare param1 to "a" then compare param1 to "c" then compare param1 to "e"
However, that's not actually what the computer is processing.

if conditions need to be evaluated to true for the if statement to run:

if ((condition1) || (condition2) || (condition3) {
    // true statement
}

And how we would code that up from our example above where we're trying to get the odd character from a parameter (param1):

if (param1 == "a" || param1 == "c" || param1 == "e") {
   var output = "Odd lowercase alpha character"; 
}

I'm also seeing people writing and statements like this:

if (param1 == "a" && param1 == "e") {
}

The problem with this is the fact that a variable can't really be two strings or two different numbers at the same time.

V Arun Kumar
@arunvkumr
Mar 26 2017 02:40
@junipberry this doesn't work in JS. result= 1, 2, 3, 4, 5 or 6; i think you don't need that line. what are you trying to do with that line anyway?
Joseph
@revisualize
Mar 26 2017 02:40
Ot doesnt work at all.
It*
Alexander Heras
@alexandermachines
Mar 26 2017 02:41
Hello can someone help me with this?
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
Joseph
@revisualize
Mar 26 2017 02:41
What code do you have?

Gist by revisualize / FreeCodeCamp - Stand in Line.js

// How do you add a number (item) to the end of an array (arr)? What does this method return?
// How do you remove the first element from an array (arr)? What does this method return?

You're supposed to:
Write a function nextInLine which has two parameters
an array (arr) and a number (item).
That part has been done for you here:

function nextInLine(arr, item) { }

Parameters are treated like variables that represent the values that get passed into your function from the function call (arguments).

Here's an example of this:

function hello(fName, uName) {
     return "Hello " + fName + " " + uName + ", How is your day?";
}
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?"

You can use the fName and uName parameters just like a variable inside of your function.

You just need to add a number (item) to the end of an array (arr).
You also need to remove the first element from an array (arr).
But, there is another part of this challenge. You need to know What the methods that do those two things return.

Alexander Heras
@alexandermachines
Mar 26 2017 02:42

function nextInLine(arr, item) {
// Your code here

return item; // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

so i gees
Joseph
@revisualize
Mar 26 2017 02:43
Okay, you havent done anything. Please read what I just posted.
juni
@junipberry
Mar 26 2017 02:46
@khaduch , I tried doing what the "Selecting from many options with Switch Statements” lessons showed. But I guess I did it wrong. Just not seeing how it went wrong. Do I just omit that result section? How would I group the count +1 and count-1 sections in the if/else section? And okay, fixed the strings to be within “”, didnt catch that ty~
CamperBot
@camperbot
Mar 26 2017 02:46
junipberry sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2679 | @khaduch |http://www.freecodecamp.com/khaduch
Alexander Heras
@alexandermachines
Mar 26 2017 02:47
oh this is what i did

function nextInLine(arr, item) {
// Your code here
testArr.push(item);
testArr.shift(0);
return item; // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

Joseph
@revisualize
Mar 26 2017 02:47
testArr isnt your parameter
testArr is a global variable that is only passed into the function for one test
Shift doesnt take an argumwnt.
Argument*
juni
@junipberry
Mar 26 2017 02:50
sorry @khaduch , I meant the
"Multiple Identical Options in Switch Statements” lesson
Alexander Heras
@alexandermachines
Mar 26 2017 02:51
ok i think im starting to get it
thanks
@revisualize
Ken Haduch
@khaduch
Mar 26 2017 02:52

@junipberry - you were correct to do the increment and decrement of the count value with the grouping of the multiple case statements.
The test and return for the count value happens after the end of the switch statement - so that final curly bracket closes the switch. Then you just test for the value of count - according to the two conditions:

The function will then return a string with the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative. The current count and the player's decision ("Bet" or "Hold") should be separated by a single space.

You just have to test of count is positive or not, and make the appropriate return, as indicated.

Joseph
@revisualize
Mar 26 2017 02:52
@junipberry look, I am going to be home soon. Do you have time or are you able to get on a video or audio chat with me and I will walk you through the lesson.
drinkwaterman
@drinkwaterman
Mar 26 2017 02:52

Hello people

if (parseInt(str[0]) === 1) {
                    return true;
 } else {return false;}

There's a problem with this code
when str[0] is a -1
it returns true. Why is that?

it even logs // 1 instead of -1 when I console log str[0]
Ken Haduch
@khaduch
Mar 26 2017 02:55
@drinkwaterman - where is this str[0] coming from?
drinkwaterman
@drinkwaterman
Mar 26 2017 02:55
@khaduch it comes from a string as the following: ("-1 (757) 622-7382")
as far as I know, a string can be accessed just like arrays through Indexes.
Ken Haduch
@khaduch
Mar 26 2017 02:56
@drinkwaterman - well, if that truly is a string, then str[0] is going to be -, that is, only the dash? Then str[1] is going to be 1.
drinkwaterman
@drinkwaterman
Mar 26 2017 02:57
'-' isn't an independent character, if it was an independent character, then why when I console.log str[0] it gives me 1? @khaduch are you sure?
silver537
@silver537
Mar 26 2017 02:58
probably your whole code then
Ken Haduch
@khaduch
Mar 26 2017 02:59

@drinkwaterman - if I run this code:

var str = "-1 (757) 622-7382";
for (var i = 0; i < str.length; i++) {
  console.log(str[i]);
}

I get the output:

-  Scratchpad/1:12:3
1  Scratchpad/1:12:3
   Scratchpad/1:12:3
(  Scratchpad/1:12:3
7  Scratchpad/1:12:3
5  Scratchpad/1:12:3
7  Scratchpad/1:12:3
)  Scratchpad/1:12:3
   Scratchpad/1:12:3
6  Scratchpad/1:12:3
2 Scratchpad/1:12:3
-  Scratchpad/1:12:3
7  Scratchpad/1:12:3
3  Scratchpad/1:12:3
8  Scratchpad/1:12:3
2

(Ignore the "Scratchpad" part, that is just from the debugger output) Basically the first character in each line is the output.

juni
@junipberry
Mar 26 2017 02:59
@khaduch , okay so I think I’m getting how I should fix it. This is my updated code:
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;
    result= "1, 2, 3, 4, 5 or 6";
      break;

    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count -=1;
     result= "10, J, Q, K, or A";
      break;

    default:
      count; 
  }

  if (card >=0) {
      return (count "Bet");
  }
  else {
      return (count "Hold");
  }
oh wait, I didnt rid my result section
its telling me I have an unexpected string in there
silver537
@silver537
Mar 26 2017 03:01
@khaduch so then the - is an individual character
Ken Haduch
@khaduch
Mar 26 2017 03:01
@drinkwaterman - parseInt('-') returns NaN, which, I think, will get your code confused...
silver537
@silver537
Mar 26 2017 03:01
you have to use a different method of getting that negative 1
drinkwaterman
@drinkwaterman
Mar 26 2017 03:01
@silver537 oh you're right. @khaduch you're totally right bro. I figured out where's the problem, I have filtered the string at the beginning of my code. when filtered '-' is gone '_'" what a mistake. Thank you.
CamperBot
@camperbot
Mar 26 2017 03:01
drinkwaterman sends brownie points to @silver537 and @khaduch :sparkles: :thumbsup: :sparkles:
:cookie: 896 | @silver537 |http://www.freecodecamp.com/silver537
:star2: 2680 | @khaduch |http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Mar 26 2017 03:01
@junipberry - you have to test count, not card, and please remove those result= lines - they are not helping anything.
juni
@junipberry
Mar 26 2017 03:02
ok, got it @khaduch , ty~
CamperBot
@camperbot
Mar 26 2017 03:02
junipberry sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:warning: junipberry already gave khaduch points
Ken Haduch
@khaduch
Mar 26 2017 03:02
@junipberry - and pay attention to the instructions: The current count and the player's decision ("Bet" or "Hold") should be separated by a single space. Do not forget the space!
juni
@junipberry
Mar 26 2017 03:03
alrighty
but I did include a space
or thought I did
drinkwaterman
@drinkwaterman
Mar 26 2017 03:04

now the problem is how to filter the string without affecting '-' this is the first code

str = str.replace(/[^0-9()]/g, '');

but when I add the '-' at the end of the range, it doesn't work

str = str.replace(/[^0-9()-]/g, '');
silver537
@silver537
Mar 26 2017 03:07
i think you have to escape that
(/[^0-9()\-]/g, '')
juni
@junipberry
Mar 26 2017 03:07
@khaduch , I’m still getting that “unexpected string” notification

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 10:
    case "J":
    case "Q":
    case "K":
    case "A":
    count -=1;
    break;

    default:
      count; 
  }

  if (count >=0) {
      return (cc "Bet");
  }
  else {
      return (cc "Hold");
  }
}
Greg Duncan
@GregatGit
Mar 26 2017 03:09
@junipberry this line is wrong return (cc "Hold");
drinkwaterman
@drinkwaterman
Mar 26 2017 03:09
@silver537 it didnt work
silver537
@silver537
Mar 26 2017 03:09
well idk. i skipped the phone number thing
juni
@junipberry
Mar 26 2017 03:10
@GregatGit , oh I just changed it from return (card “Hold”);
drinkwaterman
@drinkwaterman
Mar 26 2017 03:10
@silver537 Why :worried:
was it difficult?
juni
@junipberry
Mar 26 2017 03:11
@GregatGit , may I ask why its wrong? I’m not seeing why
Greg Duncan
@GregatGit
Mar 26 2017 03:11
@junipberry you need to be returning count
silver537
@silver537
Mar 26 2017 03:11
@junipberry they asked to return the number and hold/bet
drinkwaterman
@drinkwaterman
Mar 26 2017 03:11
it seems one of the easiest ones, it just need some fixes
silver537
@silver537
Mar 26 2017 03:11
so card + " bet"
or
card + " hold"
juni
@junipberry
Mar 26 2017 03:11
oh right!
let me fix that..
Greg Duncan
@GregatGit
Mar 26 2017 03:12
@junipberry and no ( ) are needed there
just a +
juni
@junipberry
Mar 26 2017 03:12
oh for the return line? okay~
I’ll try that
Greg Duncan
@GregatGit
Mar 26 2017 03:15
@junipberry the space is important so "5 Bet" will pass and "5Bet" will fail
juni
@junipberry
Mar 26 2017 03:15
a general question: “Can I use an 'else if’ if an ‘else’ doesnt follow it later?"
Aaron Fox
@aaronfox
Mar 26 2017 03:15
@junipberry yes you can
juni
@junipberry
Mar 26 2017 03:15
I see, @ greg. Ok cool @aaron going to try that now.
Greg Duncan
@GregatGit
Mar 26 2017 03:16
@junipberry it works but you shouldn't do that,
juni
@junipberry
Mar 26 2017 03:16
ohh
silver537
@silver537
Mar 26 2017 03:16
@junipberry it would be redundant in your situation
juni
@junipberry
Mar 26 2017 03:16
it would be redundant to specify the condition on else?
Riadh
@KWFE
Mar 26 2017 03:16

hi guys who want to help me in this challenge !!

 ```

// Setup
function abTest(a, b) {
// Only change code below this line
if (a=b,a<0)
return;

// Only change code above this line

return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

// Change values below to test your code
abTest(3,3);

```

Greg Duncan
@GregatGit
Mar 26 2017 03:17
@junipberry if you are going to use else and if else always finish with an else
juni
@junipberry
Mar 26 2017 03:17
ok, got it @ greg
Riadh
@KWFE
Mar 26 2017 03:17
// Setup
function abTest(a, b) {
// Only change code below this line
if (a=b,a<0)
return;
// Only change code above this line
return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}
// Change values below to test your code
abTest(3,3);
juni
@junipberry
Mar 26 2017 03:17
@GregatGit
silver537
@silver537
Mar 26 2017 03:17
@KWFE your if statement is bad
drinkwaterman
@drinkwaterman
Mar 26 2017 03:18
@silver537 it works on an online tool. however on javascript it doesnt which means that the idea of skipping the character is correct.
Aaron Fox
@aaronfox
Mar 26 2017 03:18
@KWFE first of all, when checking for equality use either == or ===
Greg Duncan
@GregatGit
Mar 26 2017 03:18
@KWFE you don't have , in if statement like that
Aaron Fox
@aaronfox
Mar 26 2017 03:18
@KWFE I think you mean to use or instead of a comma, which would be ||
silver537
@silver537
Mar 26 2017 03:18
@drinkwaterman what?
Ken Haduch
@khaduch
Mar 26 2017 03:19
@junipberry :point_up: March 25, 2017 11:02 PM - re-read that instruction - the current count (meaning the variable that you've been tallying the card information into) and the player's decision ("Bet" or "Hold") should be separated by a single space. Your return (cc "Bet") is not returning count and " Bet", which you would have to concatenate using string concatenation.
drinkwaterman
@drinkwaterman
Mar 26 2017 03:19
@silver537 I'm talking about regexr , how to skip '-' character.
Riadh
@KWFE
Mar 26 2017 03:19
@GregatGit @silver537 @aaronfox
i v solved it using this method but i think its wrong

// Setup
function abTest(a, b) {
  // Only change code below this line
  if (a==b,a<0)
    return;
  else if (a<0)
    return undefined;
  else if (b<0)
    return undefined;

  // Only change code above this line

  return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

// Change values below to test your code
abTest(3,3);
i don't even know why it works !!
Aaron Fox
@aaronfox
Mar 26 2017 03:21
you can shorten the two else if statements to
else if (a < 0 || b < 0) {
   return undefined;
}
if you'd like
@KWFE also remove the a<0 from your first if statement because you can't use commas in if statements like that
Ken Haduch
@khaduch
Mar 26 2017 03:22
@junipberry - another thing that you should learn how to make use of is the testing results - you can see in the results that it is expecting strings like "5 Bet", and "0 Hold", so you have to figure out how to generate those outputs. The test results give helpful information toward making the solution be correct.
feedmecode-01
@feedmecode-01
Mar 26 2017 03:23
java script is hard
Riadh
@KWFE
Mar 26 2017 03:23
@aaronfox but it says that the problem solved
@aaronfox i know it would be better to writte
  if (a==b && a<0)
drinkwaterman
@drinkwaterman
Mar 26 2017 03:24
@silver537 I tried it out of code and it worked successfully. Yeah it works that way and on javascript. Thanks man.
CamperBot
@camperbot
Mar 26 2017 03:24
drinkwaterman sends brownie points to @silver537 :sparkles: :thumbsup: :sparkles:
:warning: drinkwaterman already gave silver537 points
Riadh
@KWFE
Mar 26 2017 03:24
@GregatGit @silver537 @aaronfox thank you guys
CamperBot
@camperbot
Mar 26 2017 03:24
kwfe sends brownie points to @gregatgit and @silver537 and @aaronfox :sparkles: :thumbsup: :sparkles:
:cookie: 897 | @silver537 |http://www.freecodecamp.com/silver537
:cookie: 287 | @aaronfox |http://www.freecodecamp.com/aaronfox
:cookie: 839 | @gregatgit |http://www.freecodecamp.com/gregatgit
juni
@junipberry
Mar 26 2017 03:25
Wow I was so stuck on that one. But finally got it, thanks so much @GregatGit for your specific clarifications!
CamperBot
@camperbot
Mar 26 2017 03:25
junipberry sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 840 | @gregatgit |http://www.freecodecamp.com/gregatgit
Greg Duncan
@GregatGit
Mar 26 2017 03:25
@junipberry :+1:
@KWFE :+1:
juni
@junipberry
Mar 26 2017 03:27
ty~~ so relieved, reviewing it again now to see my initial errors
silver537
@silver537
Mar 26 2017 03:27
All languages are hard.
juni
@junipberry
Mar 26 2017 03:35
I have another general question though. I’m curious why the 'Multiple Identical Options in Switch Statements’ lesson used result=“x,y, or z” in the switch but I shouldn’t have used it in the ‘Counting Cards” lesson
well, specifically that lesson used result= "1, 2, or 3”;
Joseph
@revisualize
Mar 26 2017 03:41
@junipberry With what I feel that you're trying to accomplish with that line of code ... you shouldn't do var result = 1, 2, 3 or 4; in any context of javascript really.
jacob
@bjh2012
Mar 26 2017 03:42

function randomFraction() {

  // Only change code below this line.

  return 0;

  // Only change code above this line.
}

The instructions say, "Change randomFraction to return a random number instead of returning 0." So, I do this:
```

function randomFraction() {

// Only change code below this line.

return Math.random();

// Only change code above this line.
}
This satisfies the challenge, but how did randomFraction() change? I didn't do anything to randomFraction?

Joseph
@revisualize
Mar 26 2017 03:42
@junipberry Because later I feel that you'd try to do if (value = result) { do true stuff } which isn't really the correct logic within if conditional statements.
@junipberry NOW.. if "1, 2, or 3” is truly a string. Then sure ... use it. But, string comparisons should be exact.
and if you do.. I'd love to see a use case where a string would be "1, 2, or 3” exactly. And need to be applied to a comparison.
David Amanze
@GodKingShogun
Mar 26 2017 03:49
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             can
Herman Fassett
@HermanFassett
Mar 26 2017 03:49
@GodKingShogun what a work of art
drinkwaterman
@drinkwaterman
Mar 26 2017 03:49
What's wrong with my code, I've tested it and it works very well on my localhost.
but on freecodecamp two tests are still red, returning true when they should return false. (no such problem when tested on localhost && chrome)
function telephoneCheck(str) {

    if (str[0] === '-') {
            return false;
    }

    //FILTERING STR
    str = str.replace(/[^0-9()]/g, '');     

    //CHECK IF USER TYPED BOTH ()
    if (str.indexOf('(') !== -1 && str.indexOf(')') !== -1) {
        //CHECK IF NUM IS 10 OR 11 CHARACTER + ()
        if (str.length === 12) {
            if (str.indexOf('(') === 0 && str.indexOf(')') === 4) {
                return true;
            } else {return false;}
        } else if (str.length === 13) {
            if (str.indexOf('(') === 1 && str.indexOf(')') === 5 || str.indexOf('(') === 2 && str.indexOf(')') === 6) {
                if (parseInt(str[0]) === 1) {
                    return true;
                } else {return false;}
            } else {return false;}
        }
    }
    //IF USER TYPED ONE OF () ONLY
    if (str.indexOf('(') !== -1 && str.indexOf(')') === -1 || str.indexOf('(') === -1 && str.indexOf(')') !== -1) {
        return false;
    }
    //IF USER DIDNT TYPE () AT ALL
    if (str.indexOf('(') === -1 && str.indexOf(')') === -1) {
        if (str.length === 10) {
            return true;
        } else if (str.length === 11) {
            //CHECK IF THE FIRST NUMBER IS 1
            if (parseInt(str[0]) === 1) {
                return true;
            } else {return false;}
        } else {return false;}
    }

}



telephoneCheck("555-555-5555");
vigilante0525
@vigilante0525
Mar 26 2017 03:50
Finding a Remainder in JavaScript how do I use the % opperator? This is my only line of code...var remainder=2;
David Amanze
@GodKingShogun
Mar 26 2017 03:50
can someone take a look at this and tell me if the regular expression is looking for anything that is not a digit parenthesis or hyphen
@HermanFassett lol i dont know what that was
@drinkwaterman we are on the same challenge lol
drinkwaterman
@drinkwaterman
Mar 26 2017 03:51
@GodKingShogun Great :D
Tiffany
@tiffanymakes
Mar 26 2017 03:51
@vigilante0525 % gives you the remainder. So like 5%4 is equal to 1, because the remainder is 1.
David Amanze
@GodKingShogun
Mar 26 2017 03:52
@drinkwaterman what @tiffanymakes said lol
Tiffany
@tiffanymakes
Mar 26 2017 03:52
@bjh2012 the format for a function is function ( ) { }, where parameters go between the parentheses ( ) and code between the curly brackets { }. Your return Math.random(); is the code between the curly brackets for the randomFraction( ) function.
Herman Fassett
@HermanFassett
Mar 26 2017 03:52
lol my old solution doesn't work for telephone anymore
Mo.
@mokyox
Mar 26 2017 03:53
Hey folks, hit a bit of a stump with the Profile Lookup lesson. I'm not sure why the code isn't working. Any ideas what's wrong?

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

   for (var i = 0; i < contacts.length; i++) {
   if (contacts[i].firstName == firstName) {
     if (firstName.hasOwnProperty(prop)) {
         return contacts[i][prop];
         }
     else {return "No such contact";}
   }

    else {return "No such property";}
  }



// Only change code above this line
}
David Amanze
@GodKingShogun
Mar 26 2017 03:53
@drinkwaterman i was thinkin of a way i could write that code in two lines but it doesnt seem like thats going to be possible lol
drinkwaterman
@drinkwaterman
Mar 26 2017 03:54
@GodKingShogun you can try to exclude a range of characters using ^ + characters inside of '[]' see my code, I have filtered anything that is not a digit as well as '()'
David Amanze
@GodKingShogun
Mar 26 2017 03:54
im going to shut down in 7 mins but can someone take a look at this regex
drinkwaterman
@drinkwaterman
Mar 26 2017 03:54
@HermanFassett does that mean there's a bug ?
Joseph
@revisualize
Mar 26 2017 03:54
@mokkyun What is this: (firstName.hasOwnProperty(prop)) actually doing?
David Amanze
@GodKingShogun
Mar 26 2017 03:54
@drinkwaterman well you need to include - in it
vigilante0525
@vigilante0525
Mar 26 2017 03:54
@tiffanymakes I got what it means but I cant figure out how to input it into the code
David Amanze
@GodKingShogun
Mar 26 2017 03:54
@drinkwaterman - cant be the first character
Herman Fassett
@HermanFassett
Mar 26 2017 03:54
@drinkwaterman probably just means they added some new tests that my old code doesn't work for
David Amanze
@GodKingShogun
Mar 26 2017 03:55
@drinkwaterman this is what i have
var digit= /[^\d()-]/;
Herman Fassett
@HermanFassett
Mar 26 2017 03:55
@GodKingShogun I think he already checks that
drinkwaterman
@drinkwaterman
Mar 26 2017 03:55
@HermanFassett my code works on localhost with no problem, but on freecodecamp, it doesn't.
Mo.
@mokyox
Mar 26 2017 03:55
@revisualize Hey. It's checking to see if firstName has the property, 'prop'. Is my code wrong?
David Amanze
@GodKingShogun
Mar 26 2017 03:55
@HermanFassett ill just go jump off a building now lol
Herman Fassett
@HermanFassett
Mar 26 2017 03:55
@drinkwaterman it works for the tests that aren't passing?
Joseph
@revisualize
Mar 26 2017 03:56
@mokkyun Is firstName an object?
drinkwaterman
@drinkwaterman
Mar 26 2017 03:56
@GodKingShogun you should escape - using \ so your code would look this way
var digit= /[^\d()\-]/;
jacob
@bjh2012
Mar 26 2017 03:56
@tiffanymakes ok. that makes sense. but then the note says, "all function calls will be resolved before the return executes, so we can return the value of the Math.random() function." it kind of seems like a chicken and egg scenario. by calling the function, the return executes anyway. i'm not sure the significance.
drinkwaterman
@drinkwaterman
Mar 26 2017 03:56
@HermanFassett yes, it does.
David Amanze
@GodKingShogun
Mar 26 2017 03:56
@drinkwaterman why do i need to escape it
@drinkwaterman if it is at the end it will register as a hyphen
@drinkwaterman at least that is what i read
drinkwaterman
@drinkwaterman
Mar 26 2017 03:57

because it will read it as if you are seperating characters && creating a range as in the following examples

```

Mo.
@mokyox
Mar 26 2017 03:57
@revisualize My mistake. It's an argument of the function (variable). I should change it to an object contacts[i].firstName which is an object, right?
Joseph
@revisualize
Mar 26 2017 03:57
@mokkyun Is contacts[i].firstName an object?
drinkwaterman
@drinkwaterman
Mar 26 2017 03:57
/[A-Z]/
@GodKingShogun
Joseph
@revisualize
Mar 26 2017 03:58
@mokkyun Or is contacts[i].firstName a property value of an object?
Herman Fassett
@HermanFassett
Mar 26 2017 03:58
@drinkwaterman if you add a return false; at the very end of your function it should work then. I think it's just testing against nothing if it doesn't make any of the tests.
drinkwaterman
@drinkwaterman
Mar 26 2017 03:59
@HermanFassett it's totally true wow haha. Thank you so much. +5
CamperBot
@camperbot
Mar 26 2017 03:59
drinkwaterman sends brownie points to @hermanfassett :sparkles: :thumbsup: :sparkles:
:star2: 1720 | @hermanfassett |http://www.freecodecamp.com/hermanfassett
Mo.
@mokyox
Mar 26 2017 03:59
@revisualize It's a property value of the object.
Tiffany
@tiffanymakes
Mar 26 2017 04:00
@bjh2012 hmm I think it's just saying that Math.random() is solved before it is returned, so it's okay to return it directly. Not sure though.
Herman Fassett
@HermanFassett
Mar 26 2017 04:00
@GodKingShogun @drinkwaterman I think it should work fine for that -... I thought that the () would need to be escaped though...
in regex
I always test my regex with https://regex101.com just in case
Mo.
@mokyox
Mar 26 2017 04:01
@revisualize So I need an check the object contacts.[i] has the property prop?
Joseph
@revisualize
Mar 26 2017 04:01
@mokkyun remove the .
Tiffany
@tiffanymakes
Mar 26 2017 04:01
@vigilante0525 what do you have right now?
jacob
@bjh2012
Mar 26 2017 04:01
ok. thank you. i'm just trying to wrap my head around the logic behind the code.
drinkwaterman
@drinkwaterman
Mar 26 2017 04:01
@HermanFassett that's a great website. thanks for sharing.
CamperBot
@camperbot
Mar 26 2017 04:01
drinkwaterman sends brownie points to @hermanfassett :sparkles: :thumbsup: :sparkles:
:warning: drinkwaterman already gave hermanfassett points
Mo.
@mokyox
Mar 26 2017 04:04
@revisualize Thanks! Although my code seems to still fail.
CamperBot
@camperbot
Mar 26 2017 04:04
mokkyun sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3596 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Mar 26 2017 04:04
@mokkyun Sure.
@mokkyun One step at a time
@mokkyun ready for the next step?
Mo.
@mokyox
Mar 26 2017 04:04
@revisualize Yup!
Joseph
@revisualize
Mar 26 2017 04:04
@mokkyun So let's get on the same page about something.

@mokkyun

for ( ..... ) {
    if (evaluation) {
        return "truth";
    } else {
        return "lies";
    }
 }

This exact loop.. Does not loop. Because as we know:
The return statement ends function execution and specifies a value to be returned to the function caller.
Syntax
return [[expression]];
expression
The expression to return. If omitted, undefined is returned instead.

Mo.
@mokyox
Mar 26 2017 04:08
@revisualize I see. So I need to replace the final else with something else.
Joseph
@revisualize
Mar 26 2017 04:08
@mokkyun Do if statements require an else?
vigilante0525
@vigilante0525
Mar 26 2017 04:08
@tiffanymakes var remainder=2;
Joseph
@revisualize
Mar 26 2017 04:09
@mokkyun Let me give you another idea if I may.
@mokkyun Let's say you were at a big business event and you're quite popular (with all those skills you have) throughout the event you got handed 200 business cards (Which will remain unordered). Now, I walk up to you at the end and ask you.. Do you have a Business Card for "Jane Smith"? Now you loop look through your stack of 200 business cards. When would you tell me that you didn't have a business card for Jane?
Mo.
@mokyox
Mar 26 2017 04:09
@revisualize Nope, because if we don't need it, we don't put it in
@revisualize Once I've gone through all 200 and haven't seen one.
Joseph
@revisualize
Mar 26 2017 04:10
@mokkyun So, you're saying that after you loop look through all of the contacts cards in your array of object stack. That you'd tell me you don't have one for the individual?
hmmm....
  // code before a for loop.
for (..........) {
  // Code inside of a for loop.
}
  // code after a for loop.

function isLess(a, b) {
// Fix this code
return 10 < 15;
}

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

? i am stuck
Tiffany
@tiffanymakes
Mar 26 2017 04:12
@vigilante0525 well, you want the function to find the remainder for you. That's why you use modulo %. Sure you know the remainder is 2, but you wouldn't want to hard code the number into your function. The function wouldn't be very reusable. This is how you would format it: var remainder = a % b
Joseph
@revisualize
Mar 26 2017 04:12
@MR-Em Question.
@MR-Em When you do the function call of isLess(10, 15); what is the value of a and what is the value of b?
Mo.
@mokyox
Mar 26 2017 04:13
@revisualize Yes. Although I feel like I'm missing something here. If I had 200 business cards in a random order and I didn't know if I had one for Jane Smith, I would tell you I didn't have it once I've checked all the cards. Or I do have it once I find it.
Joseph
@revisualize
Mar 26 2017 04:14
@mokkyun If I were to ask you for a card for Jane Smith after looking at 10 cards, you happened to find it... Would you really keep looking through the stack of cards?
I don't know about you but, if I am looking for the 7 of Diamonds in a deck of playing cards... and if I found it after looking at 10 cards.. I wouldn't keep looking through the deck for the 7 of Diamonds.
Mo.
@mokyox
Mar 26 2017 04:15
@revisualize In that case, no because I've already found it. If I'm going to extrapolate for this good analogy, does this mean else should be else if? So if I do find that one card, I can return a value.
Joseph
@revisualize
Mar 26 2017 04:16
@mokkyun What purpose would having an else if solve?
Mo.
@mokyox
Mar 26 2017 04:16
@revisualize None, my mistake...
Joseph
@revisualize
Mar 26 2017 04:17
@mokkyun You don't need all of your code in the for loop.
vigilante0525
@vigilante0525
Mar 26 2017 04:18
@tiffanymakes oh that worked thank you
CamperBot
@camperbot
Mar 26 2017 04:18
vigilante0525 sends brownie points to @tiffanymakes :sparkles: :thumbsup: :sparkles:
:cookie: 329 | @tiffanymakes |http://www.freecodecamp.com/tiffanymakes
Spyrantis Theodoros
@thodorisanta
Mar 26 2017 04:18

im working on the twitch project. and when i use //maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css i cant use offset-md-3. but when i use https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css i cant use text-align: center; What is the solution on this? :/

https://codepen.io/oshikurou/pen/YZrqBy?editors=1101

Ricky Jairath
@rckjairath
Mar 26 2017 04:18
how to return undefined in Javascript
Joseph
@revisualize
Mar 26 2017 04:19
you just return undefined
Mo.
@mokyox
Mar 26 2017 04:19
@revisualize I see. Basically my ordering of statements is out of whack?
jacob
@bjh2012
Mar 26 2017 04:20
return Math.floor(Math.random() * 10);
or      return Math.floor of the product of Math.random() times 10
or      return number rounded down to the nearest whole number of the product of     
          random decimal multiplied times 10.
or     " return a random whole number between 0 and 9."
Man, that seems overly complicated.
Mo.
@mokyox
Mar 26 2017 04:20
@revisualize I didn't think about where return "No such contact"; should go.
MR-Em
@MR-Em
Mar 26 2017 04:20
@revisualize a is 10 b is 15. Are you saying i should change the numbers at the bottom? Because I've changed them but still doesn't pass.
Joseph
@revisualize
Mar 26 2017 04:21
@MR-Em You should use the parameters in your function just like how you use variables.
@mokkyun Actually.
@mokkyun With the code that I saw above in the block that you have. You just need to move 1 line
@mokkyun The code up here: https://gitter.im/FreeCodeCamp/HelpJavaScript?at=58d73b2041a045e94dca0b42 ... Just needs one line moved and edited a little.
Tiffany
@tiffanymakes
Mar 26 2017 04:23
@vigilante0525 :thumbsup: hopefully my explanation made sense to you.
MR-Em
@MR-Em
Mar 26 2017 04:23
@revisualize jbdhdjbr nothing is making srnse right now lol
Joseph
@revisualize
Mar 26 2017 04:23
@MR-Em What?
MR-Em
@MR-Em
Mar 26 2017 04:24
Maybe im over complicating it
Joseph
@revisualize
Mar 26 2017 04:24
@MR-Em You are.
@mokkyun OMG!
@mokkyun Actually, I'm wrong.
@mokkyun You have no such contact and no such property out of order.
ACK!
I need to learn to read code better.
Herman Fassett
@HermanFassett
Mar 26 2017 04:28
@GodKingShogun I just redid telephone in one line but it's pretty ugly xd
Mo.
@mokyox
Mar 26 2017 04:28
@revisualize Ha, No problem! Although my code still doesn't work hehe...
@revisualize

  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";}
  }



// Only change code above this line
}
MR-Em
@MR-Em
Mar 26 2017 04:28
@revisualize i need to do this step by step
Joseph
@revisualize
Mar 26 2017 04:29
@mokkyun Because your function isn't looping still
MR-Em
@MR-Em
Mar 26 2017 04:29
Otherwise I'll headbutt the wall. I know it's not that hard but not sure where I'm going wrong
Going right past my head
Tiffany
@tiffanymakes
Mar 26 2017 04:29
@bjh2012 Math.random() generates a decimal value between 0 and 1 (not including 1). When you multiply it by 10, you get numbers with decimals between 0 and 10 (not including 10). Math.floor() rounds the decimal number down to the closest whole number.
jacob
@bjh2012
Mar 26 2017 04:33
@tiffanymakes I see. my degree is in English, and like other foreign languages, JavaScript doesn't translate directly. I had to translate it three times to make the language match the logical translation my brain is trying to read. lol
Mo.
@mokyox
Mar 26 2017 04:33
@revisualize Pardon me again but is it because I'm returning the first value I've found and thus the code isn't continuing on to find others? How can change my return so it doesn't stop iterating through all the values?
Tiffany
@tiffanymakes
Mar 26 2017 04:34
@bjh2012 Does it make better sense now?
@bjh2012 Were you reading it from left to right?
Joseph
@revisualize
Mar 26 2017 04:35
@mokkyun Again.
jacob
@bjh2012
Mar 26 2017 04:35
@tiffanymakes Absolutely. it has to create the decimal and then multiply it before it can round it down. And yes, i'm still stuck on the reading left to right, I think.
Joseph
@revisualize
Mar 26 2017 04:35

@mokkyun
Let's say you were at a big business event and you're quite popular (with all those skills you have) throughout the event you got handed 200 business cards (Which will remain unordered). Now, I walk up to you at the end and ask you.. Do you have a Business Card for "Jane Smith"? Now you loop look through your stack of 200 business cards. When would you tell me that you didn't have a business card for Jane?

So, you're saying that after you loop look through all of the contacts cards in your array of object stack. That you'd tell me you don't have one for the individual?

  // code before a for loop.
for (..........) {
  // Code inside of a for loop.
}
  // code after a for loop.
Tiffany
@tiffanymakes
Mar 26 2017 04:36
@bjh2012 I can see how it would be tricky for your brain to get used to. Just remember PEMDAS. The order of operations: Parentheses, Exponents, Multiplication, Division, Addition, Subtraction.
jacob
@bjh2012
Mar 26 2017 04:38
@tiffanymakes Oh, yes. I think I remember something like that from Algebra. Thank you.
CamperBot
@camperbot
Mar 26 2017 04:38
bjh2012 sends brownie points to @tiffanymakes :sparkles: :thumbsup: :sparkles:
:cookie: 330 | @tiffanymakes |http://www.freecodecamp.com/tiffanymakes
Tiffany
@tiffanymakes
Mar 26 2017 04:39
@bjh2012 no problem!
Mo.
@mokyox
Mar 26 2017 04:39
@revisualize I'd look for all the contacts in my deck and if there isn't a card, I can tell you there isn't a card. So by relating this to the code, I'd tell you after the loop has executed. Am I wrong?
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 04:40

function palindrome(str) {
  // make all elements lower case   
  str.toLowerCase();

  // split the array   
  arr = str.split('');

  var expression = /[a-z]+/;
  // iterate through the array and remove anything but letters  
  lettersOnly = arr.filter(function(val) {
    if (val == expression) {
      return val;
    }

  });

  console.log(lettersOnly);

}



palindrome("abc123*");
guys need help
on the letterOnly variable
it is working if a put 'a' or 'b'
but when i try the regex
it doesnt return it
Joseph
@revisualize
Mar 26 2017 04:44
@mokkyun I'm trying to point you into a direction.
Mo.
@mokyox
Mar 26 2017 04:45

@revisualize Only once I've checked (looped) through my cards can I know if I have 'Jane Smith', right? In this case, I can tell you an answer after I've looped.

In this case, I return the value after the loop. Right?

Joseph
@revisualize
Mar 26 2017 04:46
@mokkyun What information do you need to return after the loop?
CMmz
@CMmz
Mar 26 2017 04:46
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 = count + 1;
        break;
      case (10):
      case ("J"):
      case ("Q"):
      case ("K"):
      case ("A"):
        count = count - 1;
        break;
    }

  var decision = "";

  if (count > 0)
    {
      decision = "Bet";
    }
  else
    {
      decision = "Hold";
    }

  return (count + " " + "decision");
  // 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');
This is my blackjack card counter
Is it wrong?
FCC says it is
Mo.
@mokyox
Mar 26 2017 04:47
@revisualize "No such contact". My loop is iterating through all the values in the array. If I can't find the contact in the loop then AFTER the loop I can return "No such contact". i.e I can tell you if I can that I have or don't have Jane's card after I've checked.
CMmz
@CMmz
Mar 26 2017 04:49
Oh lol I fixed it
zofrus
@zofrus
Mar 26 2017 04:49
@CMmz in your return, take your quotes off of "decision"
CMmz
@CMmz
Mar 26 2017 04:49
just had to remove "" from around the decision variable
thanks zofrus
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 04:50
@CMmz if you are trying to access the variable
nvm
anyone can help my issue above?
Tiffany
@tiffanymakes
Mar 26 2017 04:50
@CMmz you don't need parentheses around your numbers. And in your return statement, you're returning "decision" as a string even though it is a variable.
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 04:50
how can i use a regex on a if condition
Joseph
@revisualize
Mar 26 2017 04:52
@mokkyun Can you try it?
Manish Giri
@Manish-Giri
Mar 26 2017 04:53
@kauepacheco don't think you can, but you can use other things..like lookahead/lookbehind.
Tiffany
@tiffanymakes
Mar 26 2017 04:53
@kauepacheco looks like your if statement is comparing the array element to the expression /[a-z]+/, which isn't what you want. You want to .replace() the non-alphanumeric characters.
Mo.
@mokyox
Mar 26 2017 04:53
@revisualize Yup, tried it and it worked. Thanks a bunch for the probing questions and getting me to figure it out. I appreciate it.
CamperBot
@camperbot
Mar 26 2017 04:53
mokkyun sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: mokkyun already gave revisualize points
Roxroy
@roxroy
Mar 26 2017 04:57
@CMmz , you are treating decision as a string. but its a variable that shows either hold or bet
change return to return (count + " " + decision);
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 04:57
@tiffanymakes so if I iterate using for and then replace any element but alphabetical characters is the best option here? and what should I replace for?
@tiffanymakes filter() makes it so much easier
Tiffany
@tiffanymakes
Mar 26 2017 04:58
@kauepacheco they're not mutually exclusive. In my code, I used .replace() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace to replace symbols with "".
Joseph
@revisualize
Mar 26 2017 04:59
[true, true, false, false, true, false, false, true, true].filter(function (x) { return x });
[23,1,6,12,17,3,2,5,19,86,87].filter(function (x) { return x % 2 === 0 });
[23,1,6,12,17,3,2,5,19,86,87].filter(function (x) { console.log(arguments); return x % 2 === 0 });
https://repl.it/FBrn
Tiffany
@tiffanymakes
Mar 26 2017 05:00
@kauepacheco can you paste your code again? I can't remember what you had, and am having trouble scrolling to it.
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 05:01

function palindrome(str) {
  // make all elements lower case   
  str.toLowerCase();

  // split the array   
  arr = str.split('');

  var expression = /[a-z]+/;
  // iterate through the array and remove anything but letters  
  lettersOnly = arr.filter(function(val) {
    if (val == expression) {
      return val;
    }
  });
  console.log(lettersOnly);

}
palindrome("abc123*");
if i change expression for 'a': lettersOnly already has the values, i just need to join and then reverse and I would finish the challenge
I dont wanna type || 26 times
and I think this way the code would be cleaner
Manish Giri
@Manish-Giri
Mar 26 2017 05:02
that is way too much code for a palindrome challenge..
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 05:03
@Manish-Giri maybe I went too far right
@Manish-Giri do you think just a for loop would be alright
Manish Giri
@Manish-Giri
Mar 26 2017 05:04
@kauepacheco no loops needed.
you just need one regex.
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 05:04
@Manish-Giri to match with which function?
@Manish-Giri from the array.protoyype
Manish Giri
@Manish-Giri
Mar 26 2017 05:05
@Manish-Giri to match with which function?
not sure what you meant
@kauepacheco
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 05:13
@Manish-Giri how can i use regex to find any special characteres except letters?
Manish Giri
@Manish-Giri
Mar 26 2017 05:13
@kauepacheco you can use \W for that..
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 05:14
@Manish-Giri ty
CamperBot
@camperbot
Mar 26 2017 05:14
kauepacheco sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 4925 | @manish-giri |http://www.freecodecamp.com/manish-giri
Ai rui 艾瑞
@aisolae
Mar 26 2017 05:21
please help
how do i make an button toggle an element which isn't under it
?
i doubt if it's possible
but willing to give it a shot
Doni Yafi
@yafiwebdev
Mar 26 2017 05:22
what do you mean isn't under it?
Shashank Shekhar
@ashwamegh
Mar 26 2017 05:22
@aisolae can you specify which button more briefly
Ai rui 艾瑞
@aisolae
Mar 26 2017 05:22
thanks
hold on
Javier Reinoso
@JavoFrola
Mar 26 2017 05:22
Hi guys I have problems with Testing Objects for Properties. I think if I am not wrong I understand how to do it. However I do not know how to express it when is true

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

function checkObj(checkProp) {
var result;
// Your Code Here
if(myObj.hasOwnProperty() === true){
elementFound = myObj.prop();
}else{
elementFound ="Not Found";
}
return elementFound;
}

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

Ai rui 艾瑞
@aisolae
Mar 26 2017 05:22
$(document).ready(function(){
$( "#mattew" ).click(function() {
$( "#first" ).toggle(1000);
});
});
that's it
Javier Reinoso
@JavoFrola
Mar 26 2017 05:23
If someone could help me I wpuld be very grateful
juni
@junipberry
Mar 26 2017 05:23
Hey @yafiwebdev , I need help understanding what a certain lesson is trying to say. Its the “iterating through an array with a for loop” lesson, and I’m not getting why the index ends in -1 and the point of i < arr.length;Could you help explain pls~
Ai rui 艾瑞
@aisolae
Mar 26 2017 05:23
<button class="btn btn-link text-uppercase text-left" id="mattew">
and that's the button
there is an image thumbnail in btw
and a caption then the main text
Shashank Shekhar
@ashwamegh
Mar 26 2017 05:24
@JavoFrola You need to provide a property name if(myObj.hasOwnProperty(#propertyname) === true){
Ai rui 艾瑞
@aisolae
Mar 26 2017 05:24
my issue is how to make the h3 toggle the text below the big image
arturo-rios
@arturo-rios
Mar 26 2017 05:25

```function switchOfStuff(val) {
var answer = "";
// Only change code below this line
switch (val) {
case "a":
answer: "apple";
break;
case "b":
answer: "bird";
break;
case "c":
answer: "cat";
break;
default:
answer: "stuff";
}

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

// Change this value to test
switchOfStuff("a");

Phil Curran
@XLCM
Mar 26 2017 05:25
@aisolae: if you're using bootstrap, and have your js and jquery files hooked up, you shoudln't need to write extra javascript / jjquery. Also, are you trying to make different tabs for the different people? If so, take another look at the bootstrap documentation.
arturo-rios
@arturo-rios
Mar 26 2017 05:25

```function switchOfStuff(val) {
var answer = "";
// Only change code below this line
switch (val) {
case "a":
answer: "apple";
break;
case "b":
answer: "bird";
break;
case "c":
answer: "cat";
break;
default:
answer: "stuff";
}

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

// Change this value to test
switchOfStuff("a");
````

sorry guys, I am trying to solve this challenge but I just can´t-
Manish Giri
@Manish-Giri
Mar 26 2017 05:26
@arturo-rios answer=
not :
arturo-rios
@arturo-rios
Mar 26 2017 05:27
@Manish-Giri Got it! It won´t happen again.
Ai rui 艾瑞
@aisolae
Mar 26 2017 05:27
@XLCM i have created the tab and they are working perfectly
just the effect that should open hidden text
Javier Reinoso
@JavoFrola
Mar 26 2017 05:28
@shashank7200 and how could I provide that property name with a variable?
Shashank Shekhar
@ashwamegh
Mar 26 2017 05:28
@aisolae you can specify JS code to add a class when it is clicked and add the CSS code for that class which will create a toggle animation
Doni Yafi
@yafiwebdev
Mar 26 2017 05:28
@junipberry it's -1 becuase the array is zero-indexed, the first value's index is zero, so if the length is 5, then the last value would have an index of 4, so when you use i < arr.length, if it's 5 values in the array, you repeat it until 4, which is less than arr.length
Phil Curran
@XLCM
Mar 26 2017 05:28
@aisolae : hmm...kinda looks just like you're just using anchor tags to jump to different sections.
Ai rui 艾瑞
@aisolae
Mar 26 2017 05:29
@XLCM i use anchor to jump for the menu bar
Shashank Shekhar
@ashwamegh
Mar 26 2017 05:29
@JavoFrola Loop through object and assign it to a local variable, you can do it by a for loop, everytime it runs will locate your object properties
Ai rui 艾瑞
@aisolae
Mar 26 2017 05:30
@shashank7200 i don't get
Shashank Shekhar
@ashwamegh
Mar 26 2017 05:33
@aisolae I wanna say that, you can specify two classes , one before the click and a class which will be added after the user clicks it. And for the class which is going to be added you can specify the CSS property what your animations are gonna look like..and remove the class already on it, whose properties are displayed currently. using jQuery or plain JS
juni
@junipberry
Mar 26 2017 05:33
ahh, got it! ty again @yafiwebdev
CamperBot
@camperbot
Mar 26 2017 05:33
junipberry sends brownie points to @yafiwebdev :sparkles: :thumbsup: :sparkles:
:cookie: 245 | @yafiwebdev |http://www.freecodecamp.com/yafiwebdev
Doni Yafi
@yafiwebdev
Mar 26 2017 05:35
anytime :)
Ai rui 艾瑞
@aisolae
Mar 26 2017 05:36
@shashank7200 will try that now
thanks
Shashank Shekhar
@ashwamegh
Mar 26 2017 05:37
@aisolae anytime
Use this Code and Jquery for your Navigation Links, will look much better....
$(function() { $('a[href*="#"]:not([href="#"])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); if (target.length) { $('html, body').animate({ scrollTop: target.offset().top }, 1000); return false; } } }); });
Ai rui 艾瑞
@aisolae
Mar 26 2017 05:39
for the nav bar?
Shashank Shekhar
@ashwamegh
Mar 26 2017 05:40
@aisolae yeah, just add it in your script.js
and use jQuery
Ai rui 艾瑞
@aisolae
Mar 26 2017 05:40
wow, that's awesome
been thinking of how to do that
you are a saviour
@shashank7200 thanks
CamperBot
@camperbot
Mar 26 2017 05:41
aisolae sends brownie points to @shashank7200 :sparkles: :thumbsup: :sparkles:
:cookie: 121 | @shashank7200 |http://www.freecodecamp.com/shashank7200
Shashank Shekhar
@ashwamegh
Mar 26 2017 05:41
@aisolae :+1:
meng
@Eniminio
Mar 26 2017 05:42
who can help me! what's wrong?
Ai rui 艾瑞
@aisolae
Mar 26 2017 05:42
maybe i will leave that
meng
@Eniminio
Mar 26 2017 05:42

function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for(var i=0;i< multiplyAll.length;i++){
for(var j=0;j< multiplyAll[i].length;j++){
product = product * multiplyAll;
}
}
// Only change code above this line
return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);

Ai rui 艾瑞
@aisolae
Mar 26 2017 05:42
then use a search for a sticky "go back to the top" icon
Manish Giri
@Manish-Giri
Mar 26 2017 05:43
@Eniminio product = product * multiplyAll; is wrong
multiplyAll is the function's name..
so are these
for(var i=0;i< multiplyAll.length;i++){
for(var j=0;j< multiplyAll[i].length;j++){
Shashank Shekhar
@ashwamegh
Mar 26 2017 05:43
@aisolae yeah it will work too
Manish Giri
@Manish-Giri
Mar 26 2017 05:43
the array is in arr
@Eniminio
meng
@Eniminio
Mar 26 2017 05:44

function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for(var i=0;i< arr.length;i++){
for(var j=0;j<arr[i].length;j++){
product = product * arr;
}
}
// Only change code above this line
return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);

still wrong
Manish Giri
@Manish-Giri
Mar 26 2017 05:45
* arr;
meng
@Eniminio
Mar 26 2017 05:45
oh!!!
Manish Giri
@Manish-Giri
Mar 26 2017 05:45
this is the array
meng
@Eniminio
Mar 26 2017 05:45
I do it
Manish Giri
@Manish-Giri
Mar 26 2017 05:45
need to get the indiv elements
meng
@Eniminio
Mar 26 2017 05:45
thank you
Ai rui 艾瑞
@aisolae
Mar 26 2017 06:00
@shashank7200
take a look at it now
Sheetal Giri
@sheetalgiri
Mar 26 2017 06:01
hello any node js experts here?
Shashank Shekhar
@ashwamegh
Mar 26 2017 06:02
@aisolae scrollToTop should be at right bottom side. it should not float over the page
dakshdobhal
@dakshdobhal
Mar 26 2017 06:02
could someone please tell me why var k = Boolean(val) works but var k = new Boolean(val) does not?
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 06:05
When I console.log(arr) it returns the array. But when I use in the for loop it throws an error saying that I cant use .length on undefined. Why?

function findLongestWord(str) {
  var arr = str.split(" ");
  console.log(arr);
  var longest = "";
  for (var i = 0; i < arr.length; i++) {
    if (arr[i] > arr[i + 1]) {
      longest = arr[i].length;
    } else {
      longest = arr[i + 1].length;
    }
  }

  return longest.length;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Shashank Shekhar
@ashwamegh
Mar 26 2017 06:05
@dakshdobhal var k = new Boolean(val) also works... you can check it at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
Ai rui 艾瑞
@aisolae
Mar 26 2017 06:06
@shashank7200 my objective is that user can go bank to the top from anywhere in the top
page*
dakshdobhal
@dakshdobhal
Mar 26 2017 06:07
@shashank7200 , the fcc consolne says do not use boolean as constructor
Ai rui 艾瑞
@aisolae
Mar 26 2017 06:07
it's a one page site and it's too long
scrolling to the top seems tiring
Shashank Shekhar
@ashwamegh
Mar 26 2017 06:07
@aisolae it is the best practice to show it at thr right bottom and also creates a responsive design
Ai rui 艾瑞
@aisolae
Mar 26 2017 06:08
so is there a way to initiate back to the top from mid page
?
Shashank Shekhar
@ashwamegh
Mar 26 2017 06:08
@dakshdobhal may be the editor fails to test the code when declared as constructor, but for real you can use it
@aisolae use this pen to do it https://codepen.io/rdallaire/pen/apoyx
Ai rui 艾瑞
@aisolae
Mar 26 2017 06:10
i get what you mean
Shashank Shekhar
@ashwamegh
Mar 26 2017 06:12
@kauepacheco you are returning an int value, what is needed to return , the longest string or its length?
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 06:14
@shashank7200 I need to return the length... The problem is that my for loop is breaking because it says I am applying .length in an undefined object...
Shashank Shekhar
@ashwamegh
Mar 26 2017 06:14
@kauepacheco you are splitting a String in array of characters, you shouldn't do that. it will not help you to comapre the words in the string....and for the length you are checking in arr[i].length it will return 1 since it is a charater only
dakshdobhal
@dakshdobhal
Mar 26 2017 06:18
@shashank7200 the array is an array of words . that part is all right
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 06:18
@shashank7200 i fixed that, now it return it correctly for some but incorrect for others...

function findLongestWord(str) {
  var arr = str.split(" ");
  var longest = "";
  for (var i = 0; i < arr.length - 1; i++) {
    if (arr[i].length > arr[i + 1].length) {
      longest = arr[i].length;
    }
  }

  return longest;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Shashank Shekhar
@ashwamegh
Mar 26 2017 06:19
@kauepacheco :thumbsup:
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 06:20
correct - findLongestWord("The quick brown fox jumped over the lazy dog") should return a number.
incorrect - findLongestWord("The quick brown fox jumped over the lazy dog") should return 6.
incorrect - findLongestWord("May the force be with you") should return 5.
correct - findLongestWord("Google do a barrel roll") should return 6.
correct - findLongestWord("What is the average airspeed velocity of an unladen swallow") should return 8.
incorrect - findLongestWord("What if we try a super-long word such as otorhinolaryngology") should return 19.
dakshdobhal
@dakshdobhal
Mar 26 2017 06:22
@kauepacheco your logic in the for loop is not corect . you are only comparing a string to the next string , instead you should compare each string to longest
Ai rui 艾瑞
@aisolae
Mar 26 2017 06:23
yeah
that works
@shashank7200
thanks
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 06:23
@dakshdobhal ok now it is better, it got all correct but the last one

function findLongestWord(str) {
  var arr = str.split(" ");
  var longest = 0;
  for (var i = 0; i < arr.length - 1; i++) {
    if (arr[i].length > longest) {
      longest = arr[i].length;
    }
  }

  return longest;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
oh got it
nevermind, didnt get it
Shashank Shekhar
@ashwamegh
Mar 26 2017 06:24
@aisolae :thumbsup:
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 06:25
@aisolae when someone help you u should @name ty
CamperBot
@camperbot
Mar 26 2017 06:25
kauepacheco sends brownie points to @aisolae and @name :sparkles: :thumbsup: :sparkles:
:warning: @name's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
:cookie: 122 | @aisolae |http://www.freecodecamp.com/aisolae
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 06:25
like that
@aisolae @name and the word t.y
Ricky Jairath
@rckjairath
Mar 26 2017 06:25

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

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

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

Ai rui 艾瑞
@aisolae
Mar 26 2017 06:26
@ @kauepacheco thanks
Ricky Jairath
@rckjairath
Mar 26 2017 06:26
return myObj.checkProp; is not workng
Ai rui 艾瑞
@aisolae
Mar 26 2017 06:26
right ?
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 06:26
without the first @
Ai rui 艾瑞
@aisolae
Mar 26 2017 06:26
@kauepacheco thanks
CamperBot
@camperbot
Mar 26 2017 06:26
aisolae sends brownie points to @kauepacheco :sparkles: :thumbsup: :sparkles:
:cookie: 263 | @kauepacheco |http://www.freecodecamp.com/kauepacheco
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 06:26
yeah
Ai rui 艾瑞
@aisolae
Mar 26 2017 06:26
yeah, been doing that
thanks again
@kauepacheco thanks again
Kevin
@BlueLord455
Mar 26 2017 06:29
Could anyone help me out with"Convert Celsius to Fahrenheit"? Please
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 06:29
@kauepacheco got it right! ty
CamperBot
@camperbot
Mar 26 2017 06:29
sorry kauepacheco, you can't send brownie points to yourself! :sparkles: :sparkles:
Kaue Rodrigo Pacheco
@kauepacheco
Mar 26 2017 06:29
@dakshdobhal got it right ty
CamperBot
@camperbot
Mar 26 2017 06:29
kauepacheco sends brownie points to @dakshdobhal :sparkles: :thumbsup: :sparkles:
:cookie: 251 | @dakshdobhal |http://www.freecodecamp.com/dakshdobhal
meng
@Eniminio
Mar 26 2017 06:30
who can help me!

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 lookUp(firstName, prop){
// Only change code below this line
if (lookUp.firstName===contacts.firstName &&lookUP.prop===contacts.prop){
console.log(contacts.prop);
}
else if(lookUP.firstName===contacts.firstName && lookUP.prop!==contacts.prop){
console.log("No such property");
}
else{
console.log("No such contact");
}
// Only change code above this line
}

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

my code from if...
Doni Yafi
@yafiwebdev
Mar 26 2017 06:31
use return not console.log
meng
@Eniminio
Mar 26 2017 06:31
let me try
it say lookUP is not defined
Shashank Shekhar
@ashwamegh
Mar 26 2017 06:34

@rckjairath You need to use Bracket notation, when the property name is in a string , it will be:

var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Here
if( myObj.hasOwnProperty(checkProp)){
return myObj[checkProp];
}
else
return "Not Found";
}
// Test your code by modifying these values
checkObj('gift');

meng
@Eniminio
Mar 26 2017 06:36
@yafiwebdev can you help me
@shashank7200 can you help me
Doni Yafi
@yafiwebdev
Mar 26 2017 06:37
@Eniminio I don't remember the function name being lookUp
Shashank Shekhar
@ashwamegh
Mar 26 2017 06:38
@Eniminio Will try for sure!
Doni Yafi
@yafiwebdev
Mar 26 2017 06:38
@Eniminio it was lookUpProfile
meng
@Eniminio
Mar 26 2017 06:39
I dont understand
Doni Yafi
@yafiwebdev
Mar 26 2017 06:39
oh sorry
meng
@Eniminio
Mar 26 2017 06:39
what should I do
Emilio Cantón
@Cabemo
Mar 26 2017 06:39
Can anyone tell me if this is too long for the "Roman numeral Converter":
function convertToRoman(num) {
  var hi = [];
  var thousand;
  var hundred;
  var tens;
  var unit;
  var roman = {
    one:"I",
    five:"V",
    tens:"X",
    fifty:"L",
    ohundred:"C",
    fhundred:"D",
    thousand:"M"
  };

  thousand = Math.floor(num/1000);
  hundred = Math.floor((num - (thousand*1000))/100);
  tens = Math.floor((num -  ((thousand*1000) + (hundred*100)))/10);
  unit = (num - ((thousand*1000)+(hundred*100)+(tens*10)));

  //Scanning of thousands
if (num >= 1000) {
  for (var i = 0; i < thousand; i++) {
    hi.push(roman.thousand);
  }
}
  //Scanning of hundreds
  if (hundred <= 3) {
    for (var j = 0; j < hundred; j++) {
      hi.push(roman.ohundred);
    }
  }
  else if (hundred >= 4 && hundred <= 8) {
    if (hundred == 4) {
      hi.push(roman.ohundred+roman.fhundred);
    }
    else if (hundred == 5) {
      hi.push(roman.fhundred);
    }
    else if (hundred >= 6) {
      hi.push(roman.fhundred);
      for (var k = 0; k < hundred - 5; k++) {
        hi.push(roman.ohundred);
      }
    }
  }
  else if (hundred == 9) {
    hi.push(roman.ohundred + roman.thousand);
  }

  //Scanning of tens  
  if (tens <= 3) {
    for (var l = 0; l < tens; l++) {
      hi.push(roman.tens);
    }
  }
  else if (tens >= 4 && tens <= 8) {
    if (tens == 4) {
      hi.push(roman.tens+roman.fifty);
    }
    else if (tens == 5) {
      hi.push(roman.fifty);
    }
    else if (tens >= 6) {
      hi.push(roman.fifty);
      for (var m = 0; m < tens - 5; m++) {
        hi.push(roman.tens);
      }
    }
  }
  else if (tens == 9) {
    hi.push(roman.tens + roman.ohundred);
  }

  //Scanning of units
   if (unit <= 3) {
    for (var o = 0; o < unit; o++) {
      hi.push(roman.one);
    }
  }
  else if (unit >= 4 && unit <= 8) {
    if (unit == 4) {
      hi.push(roman.one+roman.five);
    }
    else if (unit == 5) {
      hi.push(roman.five);
    }
    else if (unit >= 6) {
      hi.push(roman.five);
      for (var p = 0; p < unit - 5; p++) {
        hi.push(roman.one);
      }
    }
  }
  else if (unit == 9) {
    hi.push(roman.one + roman.tens);
  }

  hi = hi.join("");



  return hi;
}

convertToRoman(944);
Doni Yafi
@yafiwebdev
Mar 26 2017 06:41
I got the wrong @Eniminio this one took me hours, you need to think what are the consequences of each iteration
meng
@Eniminio
Mar 26 2017 06:41
@yafiwebdev @shashank7200 oh!!! I know thanks
CamperBot
@camperbot
Mar 26 2017 06:41
eniminio sends brownie points to @yafiwebdev and @shashank7200 :sparkles: :thumbsup: :sparkles:
:cookie: 122 | @shashank7200 |http://www.freecodecamp.com/shashank7200
:cookie: 253 | @yafiwebdev |http://www.freecodecamp.com/yafiwebdev
Shashank Shekhar
@ashwamegh
Mar 26 2017 06:41
@Eniminio you have to check it using a For loop, since the array is of object , with each iteration, it will point to an object, then you can lookUP in that object for your property
Doni Yafi
@yafiwebdev
Mar 26 2017 06:41
you need to go through the properties and values
meng
@Eniminio
Mar 26 2017 06:42
I understand!!
thank you
Shashank Shekhar
@ashwamegh
Mar 26 2017 06:42
@Eniminio :thumbsup:
@Cabemo You should shorten your code using Switch statements,
juni
@junipberry
Mar 26 2017 06:54
guys, Im stuck on the “Nesting for Loops” section
Doni Yafi
@yafiwebdev
Mar 26 2017 06:54
yeah this one can be a pain
I hate loops generally :D
nesting or without
juni
@junipberry
Mar 26 2017 06:55
I get the logic in the instructions but not sure how it wants me to go about it
Doni Yafi
@yafiwebdev
Mar 26 2017 06:55
what have you got so far ?
juni
@junipberry
Mar 26 2017 06:55
@yafiwebdev , I think I confused myself again lol
Doni Yafi
@yafiwebdev
Mar 26 2017 06:55
haha
juni
@junipberry
Mar 26 2017 06:55
I just followed the example in tutorial bc I wasnt sure
:worried:
and added a ‘k’ element!
Doni Yafi
@yafiwebdev
Mar 26 2017 06:56
try to think it through before coding it
think of the possible results
and reset if you're confused and start over
juni
@junipberry
Mar 26 2017 06:58
hmm okay, trying to think it over
brb lol give me a few mins
might take awhile..
Doni Yafi
@yafiwebdev
Mar 26 2017 06:59
alright
take your time
juni
@junipberry
Mar 26 2017 07:05
I’m going back to the previous lesson to make sure I understood it right
to review
now Im not so sure
why do we want to iterate through an array anyway?
Doni Yafi
@yafiwebdev
Mar 26 2017 07:08
to search for something for example
you might have a huge amount of data
like contacts in a phone
when you search, it loops through all the contacts and comes back with a result
juni
@junipberry
Mar 26 2017 07:10
and we need to just specify a certain pattern for that loop?
Emilio Cantón
@Cabemo
Mar 26 2017 07:10
@shashank7200 Thanks
CamperBot
@camperbot
Mar 26 2017 07:10
cabemo sends brownie points to @shashank7200 :sparkles: :thumbsup: :sparkles:
:cookie: 123 | @shashank7200 |http://www.freecodecamp.com/shashank7200
Shashank Shekhar
@ashwamegh
Mar 26 2017 07:11
@Cabemo :thumbsup:
Doni Yafi
@yafiwebdev
Mar 26 2017 07:12
@junipberry yeah you tell it what to look for
and what result to return
Akash sharma
@AkashSharma1
Mar 26 2017 07:15
hey i have a problem on Testing Objects for properties, it is running else statement but not the if statement
Doni Yafi
@yafiwebdev
Mar 26 2017 07:16
it means the condition wasn't met
what condition do you have
Akash sharma
@AkashSharma1
Mar 26 2017 07:16
can you please check my code?
Doni Yafi
@yafiwebdev
Mar 26 2017 07:16
sure
Akash sharma
@AkashSharma1
Mar 26 2017 07:16
Modify the function checkObj to test myObj for checkProp. If the property is found, return that property's value. If not, return "Not Found". (This was the Instruction)
Doni Yafi
@yafiwebdev
Mar 26 2017 07:17
put it inside these
红色小星
@turboxing
Mar 26 2017 07:17

function myTest(val) {
if (val === 7 ) { // Change this line
return "Equal";
}
return "Not Equal";
}

// Change this value to test
myTest(10);

error?
Akash sharma
@AkashSharma1
Mar 26 2017 07:17

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

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

return "Not Found";

}

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

zhangjine
@zhangjine
Mar 26 2017 07:17
var rel;
var i = 0;
if(contacts[i].hasOwnProperty(prop)){
for(; i < contacts.length; i++){
if(firstName == contacts[i].firstName){
rel = contacts[i][prop];
}else{
rel ="No such contact";
}
}
return rel;
}else{
return "No such property";
}
"Sherlock", "likes" 应该返回 ["Intriguing Cases", "Violin"]
"Harry","likes" 应该返回一个数组
Doni Yafi
@yafiwebdev
Mar 26 2017 07:17
remove te quotes from checProp in the condition
also you don't need to put === true
zhangjine
@zhangjine
Mar 26 2017 07:18
who can tell me the question is ?
Doni Yafi
@yafiwebdev
Mar 26 2017 07:18
you just put the condition, and if it's true, the function runs
Akash sharma
@AkashSharma1
Mar 26 2017 07:19
thank you.
it worked
tech-tron
@tech-tron
Mar 26 2017 07:28

function diffArray(arr1, arr2)
{
var singles = [];
var wholeArr = arr1.concat(arr2);
for(var i = 0; i< wholeArr.length; i++){
if(wholeArr.lastIndexOf(wholeArr[i]) == wholeArr.IndexOf(wholeArr[i])){
singles += wholeArr[i];
}
}

return singles;
}

diffArray([1, "calf", 3, "piglet"], [1, "calf", 3, 4]);

it says type error: arrWhole.indexOf is not a function
saket makhija
@saketmakhija
Mar 26 2017 07:30
i need help in "check for palindrome"
@camperbot
Harsh Chandra
@HarshHC
Mar 26 2017 07:49
why and when should we objects when we have arrays?
Ray Martinez
@rayjrm
Mar 26 2017 07:52
Hey, everyone! Where's the best place to learn how to construct regex?
tech-tron
@tech-tron
Mar 26 2017 07:53
@saketmakhija its not that bad alot of prototypes
you have to have to make it all lowercase
then remove all non a-z and 0-9 chars
on the one you are going to compare it too youll have to .split it and then .reverse it and re .join it
Ray Martinez
@rayjrm
Mar 26 2017 07:56
yes, i solved the challenge, but i had to look up the regex to get it right
tech-tron
@tech-tron
Mar 26 2017 07:57
k
Ray Martinez
@rayjrm
Mar 26 2017 07:57

function palindrome(str) {

  var cleanStr = str.toLowerCase().replace(/[^0-9a-z]/g,''); 

  if (cleanStr.split('').reverse().join('') === cleanStr) {
    return true; 
  } else {
    return false;
  }
}



palindrome("eye");
I suppose I'm looking for resources to better understand the expressions
tech-tron
@tech-tron
Mar 26 2017 08:00
i just used my console.log lol, i went through the challanges real fast the first time and didnt learn nothing until i did everything with the browser's console and logged it. idk, it just felt realer that way. good luck
Ray Martinez
@rayjrm
Mar 26 2017 08:02
keepin' it realer :)
tech-tron
@tech-tron
Mar 26 2017 08:03
lol
@rayjrm maybe this link will help you https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions , coincidentally I just finished that problem too but my solution is a lot messier, I prefer the way you solved it.
Ray Martinez
@rayjrm
Mar 26 2017 08:05
:)
i could have done wihout out that extra variable but my if condition was getting crazy long
Raghav Mundra
@Raghav17
Mar 26 2017 08:28
My tweet button is not working. Please tell me what is wrong
Markus Kiili
@Masd925
Mar 26 2017 08:41
@rayjrm return cleanStr.split('').reverse().join('') === cleanStr; is better than with the if.
No need to test a Boolean when you can just return it.