These are chat archives for FreeCodeCamp/HelpJavaScript

31st
Jan 2017
Theo M.
@cnngraphics
Jan 31 2017 00:00
What is wrong with my code?
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch(answer){
    case 1:
      answer = "alpha";
      break;
    case 2:
      answer= "beta";
      break;
    case 3:
      answer = "gamma";
      break;
    case 4:
      answer= "delta";
      break;
  }


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

// Change this value to test
caseInSwitch(1);
Jason Luboff
@JLuboff
Jan 31 2017 00:00
@cnngraphics switch(val){
@cnngraphics You want your switch to be testing val since that is our passed in parameter to our function
Theo M.
@cnngraphics
Jan 31 2017 00:01
Wow.. thanks! @JLuboff
CamperBot
@camperbot
Jan 31 2017 00:01
cnngraphics sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:cookie: 737 | @jluboff |http://www.freecodecamp.com/jluboff
Jason Luboff
@JLuboff
Jan 31 2017 00:02
:+1:
Greg Duncan
@GregatGit
Jan 31 2017 00:03
@gatezh I think that biils should be the param cid
Max
@UkrainianProtein
Jan 31 2017 00:08

Hey I need help with the counting cards exercise. My instructions are:

You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card's value (see table). 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.

My code:

var count = 0;

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


  // 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');
Pieter Stokkink
@forkerino
Jan 31 2017 00:11
@gatezh your total function has a bug in the for loop. The condition should be i<array.length
Johnny
@JohnnyBizzel
Jan 31 2017 00:11

@UkrainianProtein Too much.
You will only need 3 cases

  if (card === 2 ||card === 3 || card === 4 || card === 5 || card === 6){ 
    return "5 Bet";
  } else if (card === 7 || card === 8 || card === 9){
    return "0 Hold";
    } else if (card === 10 || card === 'J' || card === 'Q' || card ==='K' || card === 'A'){
      return "-5 Hold";

and it should not be 5 Bet or -5 Hold

Because you call the function 5 times, the global variable will be changed.

Pieter Stokkink
@forkerino
Jan 31 2017 00:12
@UkrainianProtein trying to hardcode all the right solutions to the tests won't work. It will also prevent your code from working in other cases.
Johnny
@JohnnyBizzel
Jan 31 2017 00:13
@UkrainianProtein This is the global var var count = 0;
@forkerino How's it going?
Pieter Stokkink
@forkerino
Jan 31 2017 00:15
@JohnnyBizzel Quite alright. The backend projects are interesting, but eversince you spoke about that codewars problem, I've spent too much time on there. How are you?
Max
@UkrainianProtein
Jan 31 2017 00:15
@JohnnyBizzel your code isn't working either. The tests I fail are:
Cards Sequence 3, 7, Q, 8, A should return "-1 Hold"
Cards Sequence 2, J, 9, 2, 7 should return "1 Bet"
Cards Sequence 2, 2, 10 should return "1 Bet"
Cards Sequence 3, 2, A, 10, K should return "-1 Hold"
Jason Luboff
@JLuboff
Jan 31 2017 00:15
@UkrainianProtein As @forkerino mentioned, do not hardocde the answers. You need to create two statements either two if/else or a switch and a if/else. You need to first modify count based on the card and the second statement should take count and determine if you should Bet or Hold.
Johnny
@JohnnyBizzel
Jan 31 2017 00:16
@forkerino Ha ha. I'm ok. Such a lot to learn! I tried a Rank Poker hands challenge on codewars. Fun but took me 3 days!
@UkrainianProtein I never said mine was the solution. I have given you a clue.
You should use count
Pieter Stokkink
@forkerino
Jan 31 2017 00:19
@JohnnyBizzel yeah, those kata's are really challenging sometimes. I got to 4 kyu but then it gave me a couple that were so intense that my head was spinning. I decided to read up on algorithms a bit and have been practicing those. It distracts me from the projects, but it is time well spent, I reckon.
Max
@UkrainianProtein
Jan 31 2017 00:19
@JohnnyBizzel count array?
vijay-vadlamani
@vijay-vadlamani
Jan 31 2017 00:19

I am in Task Stand in Line and I am trying to achieve the solution by

function nextInLine(arr, item) {
var newItem;
if(arr !== []){
newItem = arr.shift();
} else {
newItem = item;
}
return newItem; // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];

Pieter Stokkink
@forkerino
Jan 31 2017 00:19
@vijay-vadlamani that is not the right way.
vijay-vadlamani
@vijay-vadlamani
Jan 31 2017 00:19
What am I doing wrong ? Thank you
Johnny
@JohnnyBizzel
Jan 31 2017 00:19

Hey I need help with the counting cards exercise. My instructions are:

You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card's value (see table). 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.

My code:
```

Please use me >>>

:star:
var count = 0;

:star:

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

// 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');

```

vijay-vadlamani
@vijay-vadlamani
Jan 31 2017 00:19
oh
@forkerino How would you do it ?
mmacedom
@mmacedom
Jan 31 2017 00:20

Hi guys, I'm working on challenge 189 "Golf Code" and am stuck with the first if/else statement (hole-in-one). What am I missing on it? Would appreciate a hand. Here's the code.
function golfScore(par, strokes) {
// Only change code below this line
if(strokes == 1) {
return "Hole-in-one";
}

else if(strokes <= par - 2) {
return "Eagle";
}

else if(strokes == par - 1) {
return "Birdie";
}

else if(strokes == par) {
return "Par";
}

else if(strokes == par + 1) {
return "Bogey";
}

else if(strokes == par + 2) {
return "Double Bogey";
}

else if(strokes >= par + 3) {
return "Go Home!";
}

else {
return "Change Me";
}

// Only change code above this line
}

// Change these values to test
golfScore(1, 1);

Pieter Stokkink
@forkerino
Jan 31 2017 00:20
You will need to use two of the following functions: .shift .pop .push .unshift. Pick the right ones, use the right arguments, and succeed @vijay-vadlamani
@mmacedom !
vijay-vadlamani
@vijay-vadlamani
Jan 31 2017 00:20
@forkerino ok thank you :)
CamperBot
@camperbot
Jan 31 2017 00:20
vijay-vadlamani sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:cookie: 768 | @forkerino |http://www.freecodecamp.com/forkerino
Max
@UkrainianProtein
Jan 31 2017 00:21
@JohnnyBizzel
var count = 0;
var count = +1;
var count = -1;
Johnny
@JohnnyBizzel
Jan 31 2017 00:21
@forkerino I have been trying some of the other langugages. I got to 5 kyu.
@UkrainianProtein Run your code here: http://pythontutor.com/javascript.html#mode=edit
Then come back when you can see what happens. будь ласка
mmacedom
@mmacedom
Jan 31 2017 00:22
any ideas on that solution anyone?
Pieter Stokkink
@forkerino
Jan 31 2017 00:22
@JohnnyBizzel I only speak JS so far. Will dabble a bit with Java because of a training I'm getting, but I think my main language will remain JS for the time being.
@mmacedom !
it is what you are missing.
mmacedom
@mmacedom
Jan 31 2017 00:23
the exclamation? @forkerino
Luke
@TheGenieOfTruth
Jan 31 2017 00:23
dududuuu am bored will spend a few minutes here being a bro
Pieter Stokkink
@forkerino
Jan 31 2017 00:23
@mmacedom yes
Johnny
@JohnnyBizzel
Jan 31 2017 00:23
@forkerino Me too. I am experienced with C# but am also trying PHP and Python.
Max
@UkrainianProtein
Jan 31 2017 00:24
@JohnnyBizzel
var count = 0;

function cc(card) {
  // Only change code below this line
   if (card === 2 ||card === 3 || card === 4 || card === 5 || card === 6){
    count = +1;
    return "5 Bet";
  } else if (card === 7 || card === 8 || card === 9){
    count = 0;
    return "0 Hold";
    } else if (card === 10 || card === 'J' || card === 'Q' || card ==='K' || card === 'A'){
      count = -1;
      return "-5 Hold";
    }
Pieter Stokkink
@forkerino
Jan 31 2017 00:25
@JohnnyBizzel cool. I guess it becomes easier to pick up other languages when you learn more, I just want to solidify JS so I won't start mixing syntax up when I get on with the next one.
mmacedom
@mmacedom
Jan 31 2017 00:25
@forkerino let me see if I got this right. if(strokes !== 1) {
return "Hole-in-one";?
Johnny
@JohnnyBizzel
Jan 31 2017 00:25
@UkrainianProtein Run your code here: http://pythontutor.com/javascript.html#mode=edit
будь ласка
John Nunns
@johnnunns
Jan 31 2017 00:25
@forkerino can you make any sense of this problem
Write a function called "addObjectProperty".

Given two objects and a key, "addObjectProperty" sets a new property on the 1st object at the given key. The value of that new property is the entire 2nd object.

var person1 = {
  name: 'Joe Blow',
  role: 'schlub'
};
var person2 = {
  name: 'Mr. Burns',
  role: 'supervisor'
};
addObjectProperty(person1, 'manager', person2);
console.log(person1.manager); // --> { name: 'Mr. Burns', role: 'supervisor' }

Starter Code :
function addObjectProperty(obj1, key, obj2) {
  // your code here
}
mmacedom
@mmacedom
Jan 31 2017 00:26
I tried that and it makes all of the conditions wrong @forkerino at the bottom
John Nunns
@johnnunns
Jan 31 2017 00:26
I don't see the point of the 'manager'
Pieter Stokkink
@forkerino
Jan 31 2017 00:26
@mmacedom nooooooooooooooooooo......... Look at the string. Or copy paste it from the instructions, including the !
Max
@UkrainianProtein
Jan 31 2017 00:26
@JohnnyBizzel I did run my code on the site
Johnny
@JohnnyBizzel
Jan 31 2017 00:27
@forkerino It's about finding out what is possible in each. They all have similar patterns.
Pieter Stokkink
@forkerino
Jan 31 2017 00:27
@johnnunns it will be the name of the property you add to obj1
mmacedom
@mmacedom
Jan 31 2017 00:27
@forkerino oh...I see what you mean now. Thanks for the help!
CamperBot
@camperbot
Jan 31 2017 00:27
mmacedom sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:cookie: 769 | @forkerino |http://www.freecodecamp.com/forkerino
Johnny
@JohnnyBizzel
Jan 31 2017 00:27
@UkrainianProtein So you realise the return statements are wrong.
voxgranular
@voxgranular
Jan 31 2017 00:27
@UkrainianProtein Try and do the challenge "Increment a Number with Javascript" and the one after that again. They should give you a clue about what to do with the count variable.
John Nunns
@johnnunns
Jan 31 2017 00:28
I have a feeling I know how to do this, but the wording/point of this exercise is strange @forkerino
Pieter Stokkink
@forkerino
Jan 31 2017 00:28
@JohnnyBizzel sure, I understand that. I've started reading some more general books on programming, to get the design patterns down.
Max
@UkrainianProtein
Jan 31 2017 00:28
@JohnnyBizzel well it just shows count undefined and points towards the bottom of the code I'll try to do what vox suggested
Jason Luboff
@JLuboff
Jan 31 2017 00:29
@forkerino Any books you recomend? I started reading Eloquent Javascript, but found the authors writing/teaching method not to my liking. I know "You don't know JS" is available, but haven't looked at it yet.
Pieter Stokkink
@forkerino
Jan 31 2017 00:29
@johnnunns well, objects can contain other objects. So a property of an object can point to an object.
Max
@UkrainianProtein
Jan 31 2017 00:30
@voxgranular ahh it's the ++x thing, I still don't understand the ++
Johnny
@JohnnyBizzel
Jan 31 2017 00:31

@UkrainianProtein

You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card's value (see table). 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.

Jason Luboff
@JLuboff
Jan 31 2017 00:31
++ is just shorthand for variable + 1 @UkrainianProtein
Pieter Stokkink
@forkerino
Jan 31 2017 00:31
@JLuboff I like the You Don't Know JS series. Just started JavaScript Allongé, which goes more into functional programming, looking forward to seeing where it goes.
John Nunns
@johnnunns
Jan 31 2017 00:31
any exercises on here to see how to even start this? @forkerino
Pieter Stokkink
@forkerino
Jan 31 2017 00:32
YDKJS is good, but you really need to type out some of the examples to get the full benefit.
Jason Luboff
@JLuboff
Jan 31 2017 00:32
@forkerino Thanks I'll check it out.
CamperBot
@camperbot
Jan 31 2017 00:32
jluboff sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:cookie: 770 | @forkerino |http://www.freecodecamp.com/forkerino
Jason Luboff
@JLuboff
Jan 31 2017 00:32
@forkerino I'm a better hands on learner, so I'm okay with that :+1:
Pieter Stokkink
@forkerino
Jan 31 2017 00:32
@johnnunns well do you know how to assign a value to an object key?
Max
@UkrainianProtein
Jan 31 2017 00:33
it's pissing me off that I just can't fathom this exercise. Like I'm trying to understand but I just can't. I had this issue all the time in school and teachers would keep screaming for me to understand.
Pieter Stokkink
@forkerino
Jan 31 2017 00:33
@JLuboff :+1: I prefer to not read behind my computer, so this makes the switch a little hard.
Johnny
@JohnnyBizzel
Jan 31 2017 00:34
@UkrainianProtein
var count = 0; // global var
function cc(card) {
  // Only change code below this line
  switch (card) {
    case 2:
    case 3:
    case 4: 
    case 5: 
    case 6:
        count++;
      break;
    case 7: 
    case 8: 
    case 9:
      break;
    case 10:
    case 'J': case 'Q':
    case 'K': case 'A':
      count--;
      break;


  }

  if (count < 0) return count + " Hold";
  if (count > 0) return count + " Bet";
  return "0 Hold";
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); 
cc(4);cc(5); cc(6);
Max
@UkrainianProtein
Jan 31 2017 00:34
yeah I would have never figured that out -.-
Pieter Stokkink
@forkerino
Jan 31 2017 00:34
@UkrainianProtein sounds like you had some stupid teachers. Don't worry, you'll get it, piece by piece.
Jason Luboff
@JLuboff
Jan 31 2017 00:34
@forkerino Ya...I feel the same way. I just have a hard time paying $20-30 for a book...when its readily available for free online :(
Max
@UkrainianProtein
Jan 31 2017 00:35
so case1 being card 1?
Manish Giri
@Manish-Giri
Jan 31 2017 00:35
stupid teachers
lol
John Nunns
@johnnunns
Jan 31 2017 00:35
this.key = value? @forkerino
Johnny
@JohnnyBizzel
Jan 31 2017 00:35
@UkrainianProtein This uses a switch case with "fall through" which means many cases match.
Save you typing all those OR statements
Pieter Stokkink
@forkerino
Jan 31 2017 00:35
@JLuboff true, but I have an e-reader (1 more sign that I'm getting old), which helps me read e-books offline outside in the sun.
@johnnunns yes, but use bracket notation when you have a variable name as a key.
Jason Luboff
@JLuboff
Jan 31 2017 00:36
@forkerino I have an iPad Mini...which I could use that way...but then I get easily distracted. sigh
Johnny
@JohnnyBizzel
Jan 31 2017 00:36
@UkrainianProtein Return statements should be done at the end of processing. Read the requirements back again.
Pieter Stokkink
@forkerino
Jan 31 2017 00:37
@JohnnyBizzel that return "0 Hold" could just be incorporated in the if statement.
@JLuboff my e-reader has no internet. I'm telling you, it's amazing. No distractions.
Johnny
@JohnnyBizzel
Jan 31 2017 00:37
@forkerino Sure. My code can be refactored quite a bit.
Pieter Stokkink
@forkerino
Jan 31 2017 00:38
:D
Johnny
@JohnnyBizzel
Jan 31 2017 00:38
I did this last April 27th!
Jason Luboff
@JLuboff
Jan 31 2017 00:38
@forkerino Smart!
Pieter Stokkink
@forkerino
Jan 31 2017 00:39
These days they sell them with internet (so you can buy stuff directly on the device), but I don't see the point in that, it would prevent me from focusing, I'd probably look up every reference online and get distracted as well.
@JohnnyBizzel whenever I'm helping someone here and need to look up my solution I think "OMG that is so convoluted" and then I spend some time creating better solutions. Now my counting cards function body has four short lines.
Could do it in two short and one long one, but that is just ugly.
Johnny
@JohnnyBizzel
Jan 31 2017 00:41
@forkerino Re-factoring is a great idea. I keep my original and create fiddles of improved versions.
Sergii Gatezh
@gatezh
Jan 31 2017 00:42
@forkerino yep, there it is :-/ Thanks you so much!
CamperBot
@camperbot
Jan 31 2017 00:42
gatezh sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:cookie: 771 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jan 31 2017 00:42
:+1:
Max
@UkrainianProtein
Jan 31 2017 00:42
@JohnnyBizzel I don't understand how the code would check for 5 bet or -5 hold if we haven't written a code for it to return either one of those
Pieter Stokkink
@forkerino
Jan 31 2017 00:42
@JohnnyBizzel I just comment out the old ones for reference.
Randy
@rsmorin2
Jan 31 2017 00:43
thank you @JLuboff ! Just curious to know, does the switch statement need a curly brace before it?
CamperBot
@camperbot
Jan 31 2017 00:43
rsmorin2 sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:cookie: 738 | @jluboff |http://www.freecodecamp.com/jluboff
Johnny
@JohnnyBizzel
Jan 31 2017 00:43

@JohnnyBizzel I don't understand how the code would check for 5 bet or -5 hold if we haven't written a code for it to return either one of those @UkrainianProtein

The function is called 5 times

Pieter Stokkink
@forkerino
Jan 31 2017 00:43
@UkrainianProtein the count is a global variable, which means it will keep its value after the function ends.
Max
@UkrainianProtein
Jan 31 2017 00:43
@forkerino but the count value is 0 and not 5 or -5
Pieter Stokkink
@forkerino
Jan 31 2017 00:44
So if you call it 5 times it can be anywhere between -5 and 5
You change it in the function.
Jason Luboff
@JLuboff
Jan 31 2017 00:44
@rsmorin2 Personally, I always use my braces just to keep things clean for myself. I know if/else statements do not requires braces if only a single line. I'm not 100% positive on switches
Max
@UkrainianProtein
Jan 31 2017 00:44
so cc would stand for count and card would be the number?
Jason Luboff
@JLuboff
Jan 31 2017 00:45
@forkerino @JohnnyBizzel Do either of you know if curly braces can be omitted from a switch?
Pieter Stokkink
@forkerino
Jan 31 2017 00:45
@UkrainianProtein cc is the name of the function, card is the card that is passed into that function. count is a variable in which the count up until now is stored, kind of like a running total.
@JLuboff I don't think so.
Max
@UkrainianProtein
Jan 31 2017 00:46
thanks @JLuboff @JohnnyBizzel @forkerino even though I still don't understand how count is 0 but yet can return 5 bet or -5 hold
CamperBot
@camperbot
Jan 31 2017 00:46
ukrainianprotein sends brownie points to @jluboff and @johnnybizzel and @forkerino :sparkles: :thumbsup: :sparkles:
:cookie: 772 | @forkerino |http://www.freecodecamp.com/forkerino
:star2: 1210 | @johnnybizzel |http://www.freecodecamp.com/johnnybizzel
:cookie: 739 | @jluboff |http://www.freecodecamp.com/jluboff
Johnny
@JohnnyBizzel
Jan 31 2017 00:46
@JLuboff I'm gonna go with no
Pieter Stokkink
@forkerino
Jan 31 2017 00:47
@UkrainianProtein count is only zero when the program starts. After that you call your function a couple of times and it changes.
Jason Luboff
@JLuboff
Jan 31 2017 00:47
@forkerino @JohnnyBizzel Thanks
CamperBot
@camperbot
Jan 31 2017 00:47
jluboff sends brownie points to @forkerino and @johnnybizzel :sparkles: :thumbsup: :sparkles:
:warning: jluboff already gave forkerino points
:star2: 1211 | @johnnybizzel |http://www.freecodecamp.com/johnnybizzel
Jason Luboff
@JLuboff
Jan 31 2017 00:47
@rsmorin2 The concensus seems to be, no they can not be omitted. Keep them braces!
Johnny
@JohnnyBizzel
Jan 31 2017 00:48
@UkrainianProtein If cards are all low this increases the chances of a high value card (usually worth 10)
This means you should bet (count is high...bet). If high cards come then there are less left in the deck (count is low...don't bet).
A mix of high / low means there are the same high & low cards left.
Pieter Stokkink
@forkerino
Jan 31 2017 00:49
@JLuboff nope, you'll get an unexpected token error.
if you omit {}
Jason Luboff
@JLuboff
Jan 31 2017 00:49
@forkerino Going to extra mile :+1:
Pieter Stokkink
@forkerino
Jan 31 2017 00:50
I just like to be sure about it.
Jason Luboff
@JLuboff
Jan 31 2017 00:50
@forkerino Or...would the saying be Going the extra kilometer there?
voxgranular
@voxgranular
Jan 31 2017 00:50
@UkrainianProtein
var count = 0;   // count is now 0
count++;     // count is now 1
count++;     // count is now 2
count--;     // count is now 1
count--;     // count is now 0
count--;    // count is now -1
Pieter Stokkink
@forkerino
Jan 31 2017 00:50
They'd probably say something in Portuguese. :D
voxgranular
@voxgranular
Jan 31 2017 00:52
@UkrainianProtein My code is just an example to show how ++ and -- works - it's not part of the challenge.
Jason Luboff
@JLuboff
Jan 31 2017 00:52
Well..I have a hard enough time with spanish...so I don't think I'll be excelling at Portuguese any time soon :(
OuRyoShin
@DJQTDJ
Jan 31 2017 00:52
@voxgranular just like c
Coding Machine
@EphremL
Jan 31 2017 00:53
Can someone help me with my javascript code'\
OuRyoShin
@DJQTDJ
Jan 31 2017 00:53
+= =+
if you know this you will grow....
John Nunns
@johnnunns
Jan 31 2017 00:53
@forkerino man sorry to be a pain but I'm just absolutely blanking here
failing these reqs should_add_a_property_to_the_passed_in_object_at_the_passed_in_key
should_set_the_value_at_the_passed_in_key_on_the_passe
OuRyoShin
@DJQTDJ
Jan 31 2017 00:53
@EphremL what 's up?
Coding Machine
@EphremL
Jan 31 2017 00:53
switch (user) {
    case '1':
        console.log("You defeat the dragon")
        break;
    case '2':
        console.log("You have done 50% damage, Keep it up!");
        break;
    case '3':
        console.log("You have done 25% damage, Keep it up!");
        break;
    default:
    console.log("You missed it!. Better luck next time.");
}
that's my code i need to put if statements inside the case elements .
OuRyoShin
@DJQTDJ
Jan 31 2017 00:54
@EphremL put what?
Johnny
@JohnnyBizzel
Jan 31 2017 00:54
@EphremL What is "user" for?
Pieter Stokkink
@forkerino
Jan 31 2017 00:55
@johnnunns obj1[key] = obj2; I don't know any other way to explain it any more.
OuRyoShin
@DJQTDJ
Jan 31 2017 00:55
@EphremL \' ==> '
ObjectiveCFido
@ObjectiveCFido
Jan 31 2017 00:55
Is this code correct? It's not returning anything.
array.sort(function (a, b){
  return b.length - a.length;
});
Coding Machine
@EphremL
Jan 31 2017 00:55
this is user: var user = prompt("Pick from 1-3").toUpperCase();
John Nunns
@johnnunns
Jan 31 2017 00:56
@forkerino I should have just posted my code haha. I was doing obj1.key = obj2 and getting undefined
OuRyoShin
@DJQTDJ
Jan 31 2017 00:56
@ObjectiveCFido have you ever call this function?
John Nunns
@johnnunns
Jan 31 2017 00:56
I just thought I was so far off
Coding Machine
@EphremL
Jan 31 2017 00:56
@JohnnyBizzel this is user: var user = prompt("Pick from 1-3").toUpperCase();
Margaret
@Margaret2
Jan 31 2017 00:56
@ObjectiveCFido remove space between function and (), see if that helps
Pieter Stokkink
@forkerino
Jan 31 2017 00:56
@ObjectiveCFido .sort changes the array in place, did you check it?
@johnnunns yeah, with variables bracket notation is a must.
ObjectiveCFido
@ObjectiveCFido
Jan 31 2017 00:56
@DJQTDJ No, can you tell me how I should call it when I tried to call it before it didn't seem to work.
John Nunns
@johnnunns
Jan 31 2017 00:57
oooh you even said that. I didn't understand it. Thanks for the clarification @forkerino
CamperBot
@camperbot
Jan 31 2017 00:57
johnnunns sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:cookie: 773 | @forkerino |http://www.freecodecamp.com/forkerino
Johnny
@JohnnyBizzel
Jan 31 2017 00:57
@EphremL I will pick 1 every time. Do I win?
John Nunns
@johnnunns
Jan 31 2017 00:57
what would be the difference between object[key] and object['key']
Johnny
@JohnnyBizzel
Jan 31 2017 00:58
@johnnunns "key" is a string
ObjectiveCFido
@ObjectiveCFido
Jan 31 2017 00:58
Here is my full code
var array = [ ];

array.sort(function (a, b){
  return b.length - a.length;
});

function findLongestWord(str) {
  array = str.split(" ");
  return str.length;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Coding Machine
@EphremL
Jan 31 2017 00:58
var user = prompt("You are battling a dragon , and you have only one try to kill him and have to pick a number between 1-3 and if you choose wisley you will defeat the dragon. What do you pick? 1-3").toUpperCase();
switch (user) {
    case '1':
        console.log("You defeat the dragon")
        break;
    case '2':
        console.log("You have done 50% damage, Keep it up!");
        break;
    case '3':
        console.log("You have done 25% damage, Keep it up!");
        break;
    default:
    console.log("You missed it!. Better luck next time.");
}
This is my whole code, but im trying to add logical operators and to do so i am trying to put if / else statements in every case element
Theo M.
@cnngraphics
Jan 31 2017 00:58
How can I have this show "answer" in the console?
Pieter Stokkink
@forkerino
Jan 31 2017 00:58
@johnnunns the latter would look for a property named "key", the former looks for a property with the name stored in the variable key
Theo M.
@cnngraphics
Jan 31 2017 00:58
How can I have this show "answer" in the console?http://codepen.io/cnngraphics/pen/ygprdq
Coding Machine
@EphremL
Jan 31 2017 00:58
btw @JohnnyBizzel a person can only view or play this game only once so it doesnt matter
Margaret
@Margaret2
Jan 31 2017 00:58
@ObjectiveCFido you're trying to sort a blank array
Johnny
@JohnnyBizzel
Jan 31 2017 00:58
@EphremL You don't need an if statement at the moment
Pieter Stokkink
@forkerino
Jan 31 2017 00:58
@ObjectiveCFido put that sort inside your function and it might just work. :)
John Nunns
@johnnunns
Jan 31 2017 00:58
gotcha
Randy
@rsmorin2
Jan 31 2017 00:58
@JLuboff thanks for the reply on that too man! I have been trying to get more familiar with how the functions and statements actually work
CamperBot
@camperbot
Jan 31 2017 00:58
rsmorin2 sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:warning: rsmorin2 already gave jluboff points
OuRyoShin
@DJQTDJ
Jan 31 2017 00:59
@ObjectiveCFido you juest called findLon..... not the array.sort...
John Nunns
@johnnunns
Jan 31 2017 01:00
and just to clarify though, obj.key = obj['key']
so they're both looking for a string then?
Coding Machine
@EphremL
Jan 31 2017 01:00

This is my code to it.

var user = prompt("You are battling a dragon , and you have only one try to kill him and have to pick a number between 1-3 and if you choose wisley you will defeat the dragon. What do you pick? 1-3").toUpperCase();
switch (user) {
    case '1':
        console.log("You defeat the dragon")
        break;
    case '2':
        console.log("You have done 50% damage, Keep it up!");
        break;
    case '3':
        console.log("You have done 25% damage, Keep it up!");
        break;
    default:
    console.log("You missed it!. Better luck next time.");
}

@JohnnyBizzel: These are my instructions:Add some if/else statements to your cases that check to see whether one condition and another condition are true, as well as whether one condition or another condition are true. Use && and || at least one time each.

ObjectiveCFido
@ObjectiveCFido
Jan 31 2017 01:00
@forkerino No it still doesn't return anything,
Johnny
@JohnnyBizzel
Jan 31 2017 01:01
@cnngraphics
function caseInSwitch(val)
    {

        var answer = "";

        val =prompt("What is the score?");


        switch(val){
            case "1":
            answer= "Correct";
            break;

            case "2":
            answer = "Excellent";
            break;

            case "3":
            answer = "Fabulous";
            break;

            //default:  "Ok!"
        }
            alert(answer);
        console.log(answer);
        return answer;

    }
Pieter Stokkink
@forkerino
Jan 31 2017 01:01
@ObjectiveCFido you need to return something other than the str variable.
Coding Machine
@EphremL
Jan 31 2017 01:02
I hate freecodecamp javascript teaching because its so confusing
Margaret
@Margaret2
Jan 31 2017 01:02
@ObjectiveCFido the sort works, i already tested it myself, but str.length is not what you're supposed to be returning
Coding Machine
@EphremL
Jan 31 2017 01:02
i use code academy
OuRyoShin
@DJQTDJ
Jan 31 2017 01:02
@cnngraphics
alert(answer);
console.log(answer);
return answer;
Pieter Stokkink
@forkerino
Jan 31 2017 01:03
@EphremL good for the very basics, but not enough to get good at it.
OuRyoShin
@DJQTDJ
Jan 31 2017 01:03
@JohnnyBizzel var also can not to define
ObjectiveCFido
@ObjectiveCFido
Jan 31 2017 01:03
@Margaret2 That was put there by the exercise. I removed it to test the sort here is my current code can you tell me what's wrong.
var array = [ ];

array.sort(function (a, b){
  return b.length - a.length;
});

function findLongestWord(str) {
  array = str.split(" ");
  array.sort(function (a, b){
  return b.length - a.length;
});
}

array.sort();
findLongestWord("The quick brown fox jumped over the lazy dog");
Pieter Stokkink
@forkerino
Jan 31 2017 01:04
@ObjectiveCFido You still need to return something from your function, now you'll get undefined
Coding Machine
@EphremL
Jan 31 2017 01:04
nah im doing both i find code academy and coursera more helpful @forkerino
Johnny
@JohnnyBizzel
Jan 31 2017 01:04
@DJQTDJ Gong Hei Fat Choi
Theo M.
@cnngraphics
Jan 31 2017 01:04
@forkerino still did not work
Pieter Stokkink
@forkerino
Jan 31 2017 01:04
??
Margaret
@Margaret2
Jan 31 2017 01:04
@ObjectiveCFido you shouldn't have that array.sort() line after your function, and @forkerino is right, you need to do some more steps to complete the function
k97513
@k97513
Jan 31 2017 01:04
This is what I did for that algorithm
```function findLongestWord(str) {
var wd=str.split(' ');
var len=0;
for (var i=0; i<wd.length;i++) { len=(wd[i].length > len) ? wd[i].length : len;
}
return len;
}
Pieter Stokkink
@forkerino
Jan 31 2017 01:04
@EphremL ok. Whatever rocks your boat.
k97513
@k97513
Jan 31 2017 01:04
function findLongestWord(str) { var wd=str.split(' '); var len=0; for (var i=0; i<wd.length;i++) { len=(wd[i].length > len) ? wd[i].length : len; } return len; }
OuRyoShin
@DJQTDJ
Jan 31 2017 01:05
@JohnnyBizzel thanks but ->Gung Hei Fat Choi
CamperBot
@camperbot
Jan 31 2017 01:05
djqtdj sends brownie points to @johnnybizzel :sparkles: :thumbsup: :sparkles:
:star2: 1212 | @johnnybizzel |http://www.freecodecamp.com/johnnybizzel
Margaret
@Margaret2
Jan 31 2017 01:05
* floats your boat
ObjectiveCFido
@ObjectiveCFido
Jan 31 2017 01:05
@Margaret2 Where should I have it?
Margaret
@Margaret2
Jan 31 2017 01:05
:D
@ObjectiveCFido have what?
Pieter Stokkink
@forkerino
Jan 31 2017 01:05
@Margaret2 whatever rocks your cradle
Margaret
@Margaret2
Jan 31 2017 01:06
lol
ObjectiveCFido
@ObjectiveCFido
Jan 31 2017 01:06
@Margaret2 The array.sort() line
John Nunns
@johnnunns
Jan 31 2017 01:06
for objects, is there a method that works opposite to delete? like add?
OuRyoShin
@DJQTDJ
Jan 31 2017 01:06
@k97513 what;s you put in
how do you call it ,please show me
Margaret
@Margaret2
Jan 31 2017 01:06
@ObjectiveCFido you're already sorting the array inside your function, there's no reason to have an additional array.sort() line anywhere
ObjectiveCFido
@ObjectiveCFido
Jan 31 2017 01:07
@Margaret2 Ok, but then how should I call the array.sort function?
Margaret
@Margaret2
Jan 31 2017 01:07
@ObjectiveCFido you don't have to call it
Pieter Stokkink
@forkerino
Jan 31 2017 01:07
@ObjectiveCFido the array.sort() calls it by itself.
.sort() is the call
ObjectiveCFido
@ObjectiveCFido
Jan 31 2017 01:08
@forkerino @Margaret2 Ok, sorry I was confused by what someone else told me.
OuRyoShin
@DJQTDJ
Jan 31 2017 01:08
@ObjectiveCFido just define a function
ObjectiveCFido
@ObjectiveCFido
Jan 31 2017 01:09
It seems to skip over the array.sort() and onto the return str;
var array = [ ];

array.sort(function (a, b){
  return b.length - a.length;
});

function findLongestWord(str) {
  array = str.split(" ");
  array.sort(function (a, b){
  return b.length - a.length;
});
  return str;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
It only returns the str
John Nunns
@johnnunns
Jan 31 2017 01:09
thanks @forkerino
CamperBot
@camperbot
Jan 31 2017 01:09
johnnunns sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: johnnunns already gave forkerino points
Pieter Stokkink
@forkerino
Jan 31 2017 01:09
@ObjectiveCFido Well, you tell it to return the str
Margaret
@Margaret2
Jan 31 2017 01:09
@DJQTDJ you might need to look at the instructions for this challenge to understand what he's supposed to be doing
Pieter Stokkink
@forkerino
Jan 31 2017 01:09
so that is what it does
ObjectiveCFido
@ObjectiveCFido
Jan 31 2017 01:10
@forkerino I know but why is it not returning the sorted array first?
Margaret
@Margaret2
Jan 31 2017 01:10
@ObjectiveCFido return is the output of your function, it's just giving you what you told it to output
Pieter Stokkink
@forkerino
Jan 31 2017 01:10
@ObjectiveCFido try returning the length of a certain element in your array
@ObjectiveCFido You create the array. You sort the array. You return str. That is your function. The return inside the sort function only goes back to where sort was called.
which is inside your top level function
ObjectiveCFido
@ObjectiveCFido
Jan 31 2017 01:11
@forkerino So how can I make it return the sorted array only
Margaret
@Margaret2
Jan 31 2017 01:11
yep, return b.length-a.length; only applies inside the sort function
to return the sorted array, use return in front of the array.sort line...
Pieter Stokkink
@forkerino
Jan 31 2017 01:12
@ObjectiveCFido I don't think that is what you need to do here, but that would be return array
you need to access one of the elements and get its length, though
ObjectiveCFido
@ObjectiveCFido
Jan 31 2017 01:12
Ok, that worked. Thanks @Margaret2
CamperBot
@camperbot
Jan 31 2017 01:12
objectivecfido sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:star2: 1419 | @margaret2 |http://www.freecodecamp.com/margaret2
John Nunns
@johnnunns
Jan 31 2017 01:17
I know I can look up a regex code here, but trying to know it the old fashioned way too



function convertDoubleSpaceToSingle(str) {
 var string = str.join(" ")
 return string.split(" ")

}

convertDoubleSpaceToSingle("string  with  double  spaces");
why would this tell me str.join is not a function?
Pieter Stokkink
@forkerino
Jan 31 2017 01:18
@johnnunns str is not an array
Margaret
@Margaret2
Jan 31 2017 01:18
@johnnunns because join can only be used on an array
Pieter Stokkink
@forkerino
Jan 31 2017 01:18
split first join later
Pieter Stokkink
@forkerino
Jan 31 2017 01:18
regexp would be complete overkill imo
John Nunns
@johnnunns
Jan 31 2017 01:18
if I split first it'll make it an array?
Pieter Stokkink
@forkerino
Jan 31 2017 01:19
yes
Make sure to split on two spaces
Otherwise you'll get empty array elements
John Nunns
@johnnunns
Jan 31 2017 01:20
man how long does it take to just know what's used exclusively with arrays and what can do both objects and arrays?
Pieter Stokkink
@forkerino
Jan 31 2017 01:20
or rather empty strings in your array
Margaret
@Margaret2
Jan 31 2017 01:20
@johnnunns
  • split: string -> array
  • join: array -> string
Manish Giri
@Manish-Giri
Jan 31 2017 01:20
@johnnunns read the docs
Margaret
@Margaret2
Jan 31 2017 01:20
you just gotta understand what the function is actually doing
Pieter Stokkink
@forkerino
Jan 31 2017 01:20
@johnnunns or and the error messages
but basically, you'll just get an intuitive feeling as to which functions are application on what
John Nunns
@johnnunns
Jan 31 2017 01:24
I'll read those, thanks @Manish-Giri @forkerino @Margaret2
CamperBot
@camperbot
Jan 31 2017 01:24
johnnunns sends brownie points to @manish-giri and @forkerino and @margaret2 :sparkles: :thumbsup: :sparkles:
:warning: johnnunns already gave forkerino points
:star2: 1421 | @margaret2 |http://www.freecodecamp.com/margaret2
:star2: 4009 | @manish-giri |http://www.freecodecamp.com/manish-giri
Pieter Stokkink
@forkerino
Jan 31 2017 01:25
@Manish-Giri wow, you hit 4k! Congrats
Manish Giri
@Manish-Giri
Jan 31 2017 01:25
:+1:
lol, ty ty @forkerino
CamperBot
@camperbot
Jan 31 2017 01:25
manish-giri sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:cookie: 774 | @forkerino |http://www.freecodecamp.com/forkerino
Margaret2 @Margaret2 is in shock :scream:
Manish Giri
@Manish-Giri
Jan 31 2017 01:26
:smirk_cat:
:zap:
John Nunns
@johnnunns
Jan 31 2017 01:26
It's all the help he's give me :) @forkerino
Manish Giri
@Manish-Giri
Jan 31 2017 01:26
lol
k97513
@k97513
Jan 31 2017 01:27
How should I approach the Smallest Common Multiple algorithm?
Pieter Stokkink
@forkerino
Jan 31 2017 01:27
@k97513 with caution
k97513
@k97513
Jan 31 2017 01:27
Thanks
Margaret
@Margaret2
Jan 31 2017 01:27
some people are easily helped ^ :D
Pieter Stokkink
@forkerino
Jan 31 2017 01:27
@k97513 The way I did it was to first find the scm of two numbers and then move on to the next number in the range
@Margaret2 lol
k97513
@k97513
Jan 31 2017 01:28
Ah, thanks
Thanks @forkerino
CamperBot
@camperbot
Jan 31 2017 01:28
k97513 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:cookie: 775 | @forkerino |http://www.freecodecamp.com/forkerino
John Nunns
@johnnunns
Jan 31 2017 01:28
you haven't caught me on a bad day yet @Margaret2 haha
Pieter Stokkink
@forkerino
Jan 31 2017 01:30
@k97513 it will also help if your range is sorted in the right order.
Margaret
@Margaret2
Jan 31 2017 01:30
@johnnunns u could never be as bad as this guy in the main room who was just spamming the tests + "how u do this" for one of the MOST BASIC js challenges like 10 times
finally he somehow figured it out and then just started right off spamming tests + "how u do this" for the next one :sob:
Manish Giri
@Manish-Giri
Jan 31 2017 01:32
I'm gonna do that now
and guess who am gonna tag
Juriel Garcia
@Garciaj007
Jan 31 2017 01:32
Hi there guys! Im sort of stuck in the palindrome section, can someone help me, and see if i messed this line of code up? str.replace(/[&\/\#,+()$~%.'"-_:*?<>{}]/gi, ''); thanks!
Margaret
@Margaret2
Jan 31 2017 01:32
a should have a value of 6. how u do this@manish-giri
a should have a value of 6. how u do this@manish-giri
Manish Giri
@Manish-Giri
Jan 31 2017 01:32
lol
Margaret
@Margaret2
Jan 31 2017 01:33
@forkerino ooh the sting on that one :bee: :laughing:
Juriel Garcia
@Garciaj007
Jan 31 2017 01:33
@forkerino #IMASTUPIDPEOPLE
Pieter Stokkink
@forkerino
Jan 31 2017 01:33
@Garciaj007 no you are not.
fikstoday
@fikstoday
Jan 31 2017 01:33
hi stuck in javascript camelcase for StudLyCapVar,please assist
Stephen James
@sjames1958gm
Jan 31 2017 01:33
@Garciaj007 Did you assign the result of replace to a variable
Pieter Stokkink
@forkerino
Jan 31 2017 01:33
@Garciaj007 although your regex is making my eyes hurt.
Stephen James
@sjames1958gm
Jan 31 2017 01:34
@fikstoday studlyCapVar
Manish Giri
@Manish-Giri
Jan 31 2017 01:34
@fikstoday what's the problem?
John Nunns
@johnnunns
Jan 31 2017 01:34
@Margaret2 let me know if I ever come close to that :)
Juriel Garcia
@Garciaj007
Jan 31 2017 01:34
@sjames1958gm noooooo.....
Niketan Moon
@niketanmoon
Jan 31 2017 01:34
Need help with the code for profile lookup
Testcases dont pass
John Nunns
@johnnunns
Jan 31 2017 01:35
hey quick question though, I'm always interested in solving codes more concisely. So I'm asking if this code is optimal:
function getAllLetters(str) {
  if(!str.length){
      return []
  }
  return str.split("")
}
Margaret
@Margaret2
Jan 31 2017 01:35
@johnnunns i am more passive-aggressive than that, if i tell you to go talk to revisualize, you'll know i'm fed up :joy:
Pieter Stokkink
@forkerino
Jan 31 2017 01:35
aaaargh it is 1.34 am here. I'm turning in. Night night! Happy Coding!
forkerino @forkerino sleeps
John Nunns
@johnnunns
Jan 31 2017 01:35
hahaha @Margaret2
Stephen James
@sjames1958gm
Jan 31 2017 01:35
@niketanmoon You can post - don't post the contacts
John Nunns
@johnnunns
Jan 31 2017 01:35
for this piece of code I'm asking - function getAllLetters(str) {
if(!str.length){
return []
}
return str.split("")
}
sorry, wrong copy
Niketan Moon
@niketanmoon
Jan 31 2017 01:36

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
}

// Change these values to test your function
lookUpProfile("Kristian", "lastName");

John Nunns
@johnnunns
Jan 31 2017 01:36
  • If given an empty string, it should return an empty array.
fastest way to do that is actually write out the if statement?
Manish Giri
@Manish-Giri
Jan 31 2017 01:36
@johnnunns
!str.length ? [] : str.split("");
Stephen James
@sjames1958gm
Jan 31 2017 01:36
@johnnunns
return (str.lenght) ? str.split('') : []
Margaret
@Margaret2
Jan 31 2017 01:37
could not type fast enough ^^
Niketan Moon
@niketanmoon
Jan 31 2017 01:37
I have even tried using lookUpProfile function
Stephen James
@sjames1958gm
Jan 31 2017 01:37
@niketanmoon You need to test all the contacts before return no such contact
John Nunns
@johnnunns
Jan 31 2017 01:37
so the question mark is basically an if statement?
Manish Giri
@Manish-Giri
Jan 31 2017 01:37
yeah
Margaret
@Margaret2
Jan 31 2017 01:37
@johnnunns they're abbreviated if statements, aka ternary operators
and the : is the else
John Nunns
@johnnunns
Jan 31 2017 01:38
what about the ':'
Manish Giri
@Manish-Giri
Jan 31 2017 01:38
:zap: ? "Margaret H" : "Manish Giri"
Stephen James
@sjames1958gm
Jan 31 2017 01:38
@johnnunns It is an "if" that also is an expression so it can be used in assignment or return
John Nunns
@johnnunns
Jan 31 2017 01:38
oh
gotcha
Niketan Moon
@niketanmoon
Jan 31 2017 01:38
Thanks
John Nunns
@johnnunns
Jan 31 2017 01:38
thanks @sjames1958gm
CamperBot
@camperbot
Jan 31 2017 01:38
johnnunns sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5620 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
fikstoday
@fikstoday
Jan 31 2017 01:40
@sjames1958gm @Manish-Giri got it
John Nunns
@johnnunns
Jan 31 2017 01:41
alright I knew they could only stay so easy
I figured this out before but had to use a little more complicated of code and needed a lot of help. It's a count characters problem
Write a function called "countCharacter".

Given a string input and a character, "countCharacter" returns the number of occurences of a given character in the given string.

var output = countCharacter('I am a hacker', 'a');
console.log(output); // --> 3

Starter Code :
function countCharacter(str, char) {
  // your code here
}
I've thought first to split the string into individual characters
would I then do a for loop and count++?
or maybe a higher order function now that I've made it into an array after splitting
Margaret
@Margaret2
Jan 31 2017 01:44
@johnnunns lol i just now solved it with a single line :laughing:
John Nunns
@johnnunns
Jan 31 2017 01:44
don't tell me that! @Margaret2
Margaret
@Margaret2
Jan 31 2017 01:44
just remove all the a's and get the length of what's left
John Nunns
@johnnunns
Jan 31 2017 01:45
I had a really complicated (for me :) ) that required a regex method
Margaret
@Margaret2
Jan 31 2017 01:45
although splitting it into an array was my first thought too, and then you could just use .filter() on the array
John Nunns
@johnnunns
Jan 31 2017 01:45
ok and return char.length
Margaret
@Margaret2
Jan 31 2017 01:45
yeah, just now, i used replace with a simple regex
Stephen James
@sjames1958gm
Jan 31 2017 01:45
@johnnunns Regex is a way to remove the letter - or you can use a regex to match and count the matches
Margaret
@Margaret2
Jan 31 2017 01:45
to get rid of all the non-a characters
David Amanze
@GodKingShogun
Jan 31 2017 01:46
can someone take a look at my js for my weather app. everytime i click my button i want the text to change between Celsius and Fahrenheit. so far i have it that the first time i click my button it goes to Fahrenheit but the next time i click my button it stays on Fahrenheit instead of reverting back to celsius
$(document).ready(function(){
  $.getJSON("http://ip-api.com/json",function(data){
    var lat=data.lat;
    var lon=data.lon;
  $.getJSON("http://api.openweathermap.org/data/2.5/weather?lat="+lat+"&lon="+lon+"&units=metric&APPID=6b5216c389dc27fe53457d96bc7aae93", function(cool) {
  $(".celsius").html(cool.main.temp);

  });
    });
  $(".btn").on("click", function(){
$(".btn").html("Fahrenheit");
  });
  });
Margaret
@Margaret2
Jan 31 2017 01:47
@GodKingShogun because the only thing you have in your click function is .html("Fahrenheit")
Stephen James
@sjames1958gm
Jan 31 2017 01:47
@GodKingShogun You need to test the current state so you can swap between the two
Margaret
@Margaret2
Jan 31 2017 01:48
you need to use some sort of if statement to check whether the current temp is C or F before you decide what text to put in the button
Niketan Moon
@niketanmoon
Jan 31 2017 01:51
still lost
David Amanze
@GodKingShogun
Jan 31 2017 01:51
@Margaret2 @sjames1958gm would i be able to say something like if button.text===fahrenheit
@niketanmoon what are you lost with
Niketan Moon
@niketanmoon
Jan 31 2017 01:52

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";
  }
 return contacts[i][prop];
}
else {
  return "No such contact";
}

}

Margaret
@Margaret2
Jan 31 2017 01:52
@GodKingShogun sure
Stephen James
@sjames1958gm
Jan 31 2017 01:52
@GodKingShogun Something like that - not sure what the jquery command is to get the value but that is how
David Amanze
@GodKingShogun
Jan 31 2017 01:52
@Margaret2 do you know the jquery command
Niketan Moon
@niketanmoon
Jan 31 2017 01:52
@sjames1958gm can you be more specific
Margaret
@Margaret2
Jan 31 2017 01:53
@GodKingShogun text or html would probably work
Niketan Moon
@niketanmoon
Jan 31 2017 01:53
cant read the whole contacts
Margaret
@Margaret2
Jan 31 2017 01:53
@niketanmoon take out the second return contacts[i] prop; line, that shouldn't be there i don't think
Niketan Moon
@niketanmoon
Jan 31 2017 01:54
still no luck
Margaret
@Margaret2
Jan 31 2017 01:55
@niketanmoon also, you should not return "No such contact" until you have gone through the whole array, so that line needs to be outside of your for loop
Niketan Moon
@niketanmoon
Jan 31 2017 01:57
Thanks @Margaret2
CamperBot
@camperbot
Jan 31 2017 01:57
niketanmoon sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:star2: 1423 | @margaret2 |http://www.freecodecamp.com/margaret2
John Nunns
@johnnunns
Jan 31 2017 01:57
ok, started with the split before I moved on to regex, but I'm stumbling somewhere here @Margaret2
function countCharacter(str, char) {

    var string = str.split("")
  return string.filter(function(char){
      return char.length
  })

}


countCharacter('I am a hacker', 'a');
Niketan Moon
@niketanmoon
Jan 31 2017 01:58
Thanks @sjames1958gm
CamperBot
@camperbot
Jan 31 2017 01:58
niketanmoon sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
David Amanze
@GodKingShogun
Jan 31 2017 01:58
@Margaret2 by the way button.html is referring to the button i created in my html. can i still use the button.html
CamperBot
@camperbot
Jan 31 2017 01:58
:star2: 5621 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Margaret
@Margaret2
Jan 31 2017 01:58
@johnnunns don't need a regex inside filter, just need to check if the character is an "a" or not
@GodKingShogun html can both "get" and "set":
this.html(); // gets html
this.html("blabla"); // sets html to "blabla"
John Nunns
@johnnunns
Jan 31 2017 01:59
I didn't realize I had a regex inside
Margaret
@Margaret2
Jan 31 2017 02:00
@johnnunns you don't :D but you said you were gonna move on to it
so i just assumed haha
John Nunns
@johnnunns
Jan 31 2017 02:01
no I was going to try and solve both ways
but i started with the longer way so I wanted to finish it
David Amanze
@GodKingShogun
Jan 31 2017 02:02
@Margaret2 is this how i should have it set up
  $(".btn").on("click", function(){
    if(".btn".html==="Celsius") {
$(".btn").html("Fahrenheit");
    } else if(".btn".text==="Fahrenheit"){
      $(".btn").html("Celsius");
    }

    });
  });
Margaret
@Margaret2
Jan 31 2017 02:04
@GodKingShogun pretty much, check with console log to make sure you're actually getting the values you want. Remember to include proper jquery syntax in your if statements
so like $(".btn").html(), not ".btn".html
John Nunns
@johnnunns
Jan 31 2017 02:05
function countCharacter(str, char) {
    count =0
    var string = str.split("")
  return string.filter(function(i){
      if (i === char){
         return i.length
      }
  })


}


countCharacter('I am a hacker', 'a');
I have this returning [a, a, a]
k97513
@k97513
Jan 31 2017 02:05
Are the algorithm challenges ranked in order of difficulty? Because I'm getting hard ones then right immediately afterwards really easy ones
David Amanze
@GodKingShogun
Jan 31 2017 02:06
@Margaret2 someone tried to explain to me how to use the console.log but i didn't really get it. can you explain it to me
k97513
@k97513
Jan 31 2017 02:06
Console.log is used to log information from within a function. This can be accessed from the Developer tools (f12)
This is generally used to debug your code
Margaret
@Margaret2
Jan 31 2017 02:07
@GodKingShogun console.log( whatever value or function you want to check);
Muhammad Muhktar Musa
@mcube25
Jan 31 2017 02:07

currently on the friendly date challenge but my code is refusing to pass can i have someone help please check it for me function makeFriendlyDates(arr) {
var month= ['January','February','March','April','May','June','July','August','September','October','November','December'];
//create date object for strt and end date
var startDate= new Date(arr[0]),
endDate= new Date(arr1);
var startYear= startDate.getFullYear(),
startMonth= startDate.getMonth(),
startDay= startDate.getDate();
var endYear= endDate.getFullYear(),
endMonth= endDate.getMonth(),
endDay= endDate.getDate();
var myDate= new Date();
var myMonth= myDate.getMonth();
function addEnding(day){
if(day===1 || day===21 || day===31){
return day + 'st';
}else if(day===2 || day===22){
return day +'nd';
}else if (day===3 || day===23){
return day + 'rd';
}else{
return day + 'th';
}
}
if (startDate.getFullYear()===endDate.getFullYear()){
return [month[startMonth] + '' + addEnding(startDay) + ',' + startYear];
}else if (startYear===endYear && startMonth===endMonth){
return [month[startMonth] + '' + addEnding(startDay),addEnding(endDay)];
}else if (startYear=== new Date().getFullYear() && (startYear===endYear ||startYear===endYear -1)||startYear===endYear && startMonth != endMonth){
return [month[startMonth] + '' + addEnding(startDay),month[endMonth] + '' + addEnding(endDay)];
}else{
return [month[startMonth] + '' + addEnding(startDay) + ',' + startYear,month[endMonth] + '' + addEnding(endDay) + ',' + endYear];
}
return arr;
}

makeFriendlyDates(['2016-07-01', '2016-07-04']);

John Nunns
@johnnunns
Jan 31 2017 02:09
@Margaret2 would you mind taking a look up there and seeing why that doesn't return the amount of 'a's?
David Clark
@DavidDoes
Jan 31 2017 02:11
So, I'm way further than I should be to be having this issue, but my HTML file is not linking to my js file for some reason...
Margaret
@Margaret2
Jan 31 2017 02:11
@johnnunns why the heck would you return the length of a single character
David Clark
@DavidDoes
Jan 31 2017 02:11
<head>
<script type="text/javascript" src="colorchanger.js"></script>
</head>
John Nunns
@johnnunns
Jan 31 2017 02:12
I thought it would loop through each character
@Margaret2
Margaret
@Margaret2
Jan 31 2017 02:12
@johnnunns just return i === char inside the filter function
and then after you filter the array, get the length of the array
Bryan Reese
@breese8009
Jan 31 2017 02:13
function addToBack(arr, element) {
    arr[element]=element;
return arr;
}
addToBack([1,2], 3)
//can someone tell me why this returns with an empty string in the array and how to I get rid of it?
Reggie
@Reggie01
Jan 31 2017 02:13
@k97513 I think the algorithm challenges tend to get harder. You probably just have more mastery of some concepts then others.
k97513
@k97513
Jan 31 2017 02:14
Thanks @Reggie01
CamperBot
@camperbot
Jan 31 2017 02:14
k97513 sends brownie points to @reggie01 :sparkles: :thumbsup: :sparkles:
:cookie: 389 | @reggie01 |http://www.freecodecamp.com/reggie01
Margaret
@Margaret2
Jan 31 2017 02:14
@breese8009 array counting starts from 0, so 0, 1, 2, 3, arr[3] is the fourth position in the array. You should really be using .push() for this
armynational
@armynational
Jan 31 2017 02:16

what needs to be fixed in this to make var myStr to say Hello World

// Setup
var myStr = "Jello World";

// Only change code below this line

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

Manish Giri
@Manish-Giri
Jan 31 2017 02:16
myStr= -[0]+H;
what is this?
David Clark
@DavidDoes
Jan 31 2017 02:16
Can someone help me figure out why my js file is not linking to my HTML file?
armynational
@armynational
Jan 31 2017 02:17
my best guess @Manish-Giri
David Clark
@DavidDoes
Jan 31 2017 02:17
<head>
<script type="text/javascript" src="colorchanger.js"></script>
    <title>
        Color Changer
    </title>
</head>
Margaret
@Margaret2
Jan 31 2017 02:17
@armynational you can't use = to set a single letter inside a string, you have to change the whole string
Manish Giri
@Manish-Giri
Jan 31 2017 02:17
@armynational first thing is, strings are immutable, so you cant' modify each letter of a string
you can just assign a new string to the variable instead
Margaret
@Margaret2
Jan 31 2017 02:18
for example
var str = "old string";
str = "new string";
Manish Giri
@Manish-Giri
Jan 31 2017 02:18
so like
var str = "army";
str = "national";
Margaret
@Margaret2
Jan 31 2017 02:18
lol great minds think alike :joy:
Manish Giri
@Manish-Giri
Jan 31 2017 02:18
uhh
yeah
:heart_eyes_cat:
armynational
@armynational
Jan 31 2017 02:19

// Setup
var myStr = "Jello World";

// Only change code below this line

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

@Manish-Giri @Margaret2 this?

Manish Giri
@Manish-Giri
Jan 31 2017 02:19
still need to remove this - myStr[0] = "H"; because it's still wrong
@armynational
restrepomich
@restrepomich
Jan 31 2017 02:20
Hey guys, can someone shed some light as to what I'm doing wrong here:
monkeyfingerz
@monkeyfingerz
Jan 31 2017 02:20

i feel like i'm really far off and am frustrated could someone better explain what will work? function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
celsius*=9;
celsius+=32;

celsius/=5;

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

// Change the inputs below to test your code
convertToF(30);

restrepomich
@restrepomich
Jan 31 2017 02:20

var myVar = 87;

// Only change code below this line
myVar = ++myVar;

Margaret
@Margaret2
Jan 31 2017 02:21
@restrepomich the whole point of using ++ is that you don't have to use = with it
monkeyfingerz
@monkeyfingerz
Jan 31 2017 02:21
++ is a shortcut
Manish Giri
@Manish-Giri
Jan 31 2017 02:21
@armynational although there is a slight difference between ++myVar and myVar++, for this challenge you should use myVar++
restrepomich
@restrepomich
Jan 31 2017 02:21
@Margaretmcrawf Ohh I see!
Margaret
@Margaret2
Jan 31 2017 02:21
@Manish-Giri you don't think it would work either way for the challenge?
Margaretmcrawf lol
restrepomich
@restrepomich
Jan 31 2017 02:22
@Margaret2 thank you so much!
CamperBot
@camperbot
Jan 31 2017 02:22
restrepomich sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:star2: 1425 | @margaret2 |http://www.freecodecamp.com/margaret2
restrepomich
@restrepomich
Jan 31 2017 02:22
That totally worked :)
Margaret
@Margaret2
Jan 31 2017 02:22
@restrepomich no prob :D :+1:
Bill
@braunyb
Jan 31 2017 02:23

what am I doing wrong. I can't get my text to output. I've tried a bunch of different ways. Thanks

function reuseFunction(){
console.log("Write Reusable JavaScript with Functions");
}
console.log(reuseFunction)();

John Nunns
@johnnunns
Jan 31 2017 02:23
struggle bus is real @Margaret2
function countCharacter(str, char) {

    var string = str.split("")
  return string.filter(function(i){
      return i === char

  })



}


countCharacter('I am a hacker', 'a');
David Clark
@DavidDoes
Jan 31 2017 02:23

Help me read this error?

Uncaught TypeError: Cannot read property 'addEventListener' of null

CamperBot
@camperbot
Jan 31 2017 02:23
no wiki entry for: me read this erroruncaught typeerror cannot read property addeventlistener of null
John Nunns
@johnnunns
Jan 31 2017 02:23
for the life of me I can't figure out how to return the length of my filtered array
Margaret
@Margaret2
Jan 31 2017 02:23
@johnnunns ...... .length
Ashan Mohammed
@AshanMohammed
Jan 31 2017 02:23
hello, Can anybody help me with freecodecamp random quotes challenge. I have done everything except tweeting the quote directly from the site.
Can anybody help with it??
John Nunns
@johnnunns
Jan 31 2017 02:24
I've tried that
return string.length, char.length, etc
Felix Blaquiere
@yulprojects
Jan 31 2017 02:24
someone help me with lvl 203!
monkeyfingerz
@monkeyfingerz
Jan 31 2017 02:24

i feel like i'm really far off and am frustrated could someone better explain what will work? function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
celsius*=9;
celsius+=32;

celsius/=5;

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

// Change the inputs below to test your code
convertToF(30);

John Nunns
@johnnunns
Jan 31 2017 02:24
just keeps returning ['a', 'a', 'a']
Margaret
@Margaret2
Jan 31 2017 02:25
@johnnunns either assign the filtered array to its own variable and get the length of that variable, or just put .length right after the filter function
arr.filter( blablablabla).length
John Nunns
@johnnunns
Jan 31 2017 02:26
I did not know you could do that
that's clutch, thanks
Margaret
@Margaret2
Jan 31 2017 02:26
it's called method chaining, you can also do stuff like string.split('').reverse().join('')
Manish Giri
@Manish-Giri
Jan 31 2017 02:26
:disappointed:
Bill
@braunyb
Jan 31 2017 02:26

I tried this too

function reuseFunction(){
console.log("Write Reusable JavaScript with Functions");
}
document.write(reuseFunction());

Manish Giri
@Manish-Giri
Jan 31 2017 02:26
@Margaret2 I dunno, my brain hurts to think about it..
Margaret
@Margaret2
Jan 31 2017 02:26
@Manish-Giri what?
John Nunns
@johnnunns
Jan 31 2017 02:27
and on that note. I'm getting off here. Forgetting I could set it to a variable is a sign I should be done fore the day :)
Manish Giri
@Manish-Giri
Jan 31 2017 02:27
++myVar and myVar++
Felix Blaquiere
@yulprojects
Jan 31 2017 02:27
can someone help me with lvl 203
monkeyfingerz
@monkeyfingerz
Jan 31 2017 02:27
@Manish-Giri could you help me
Margaret
@Margaret2
Jan 31 2017 02:27
@johnnunns haha have a good night! :sparkles:
John Nunns
@johnnunns
Jan 31 2017 02:27
thanks all, can't wait to bug everyone tomorrow! :)
Manish Giri
@Manish-Giri
Jan 31 2017 02:27
@monkeyfingerz yes, with?
Margaret
@Margaret2
Jan 31 2017 02:27
@johnnunns wait, do you wanna see my code for that
Manish Giri
@Manish-Giri
Jan 31 2017 02:27
@monkeyfingerz this is wrong
celsius*=9;
celsius+=32;
celsius/=5;
John Nunns
@johnnunns
Jan 31 2017 02:27
oh yes please actually
I was going to ask
monkeyfingerz
@monkeyfingerz
Jan 31 2017 02:28

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
celsius*=9;
celsius+=32;

celsius/=5;

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

// Change the inputs below to test your code
convertToF(30);

Margaret
@Margaret2
Jan 31 2017 02:28
@johnnunns i just tested it in my console, but i was gonna do str.replace(/[^a]/gi, "").length;
Manish Giri
@Manish-Giri
Jan 31 2017 02:28
your formula should be varF = value_in_celsius * 9/5 + 32
Ron Laniado
@ronlaniado
Jan 31 2017 02:28
Can somebody please help me with the "Word Blanks" unit in FreeCodeCamp???
Margaret
@Margaret2
Jan 31 2017 02:28
a was the character i was checking for btw
Felix Blaquiere
@yulprojects
Jan 31 2017 02:28
can someone help me with lvl 203
Margaret
@Margaret2
Jan 31 2017 02:28
@johnnunns i guess that would be a little hard to get it to work with a variable
John Nunns
@johnnunns
Jan 31 2017 02:29
looks like it works but it's missing a few reqs.
Margaret
@Margaret2
Jan 31 2017 02:29
would probably just do a function like you did inside your filter
but still, one line :D
John Nunns
@johnnunns
Jan 31 2017 02:29
should_count_the_number_of_times_a_character_occurs_in_a_string
should_count_0_if_the_character_does_not_occur_in_a_string
should_count_0_if_the_character_is_an_empty_string
Felix Blaquiere
@yulprojects
Jan 31 2017 02:30
can someone help me with lvl 203
Margaret
@Margaret2
Jan 31 2017 02:31
oh well, i will try to fix it and let you know tomorrow :D
John Nunns
@johnnunns
Jan 31 2017 02:31
np thanks again! @Margaret2
CamperBot
@camperbot
Jan 31 2017 02:31
johnnunns sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:star2: 1426 | @margaret2 |http://www.freecodecamp.com/margaret2
Margaret
@Margaret2
Jan 31 2017 02:31
:smile:
Felix Blaquiere
@yulprojects
Jan 31 2017 02:33
can someone help me with lvl 203
Ron Laniado
@ronlaniado
Jan 31 2017 02:33
Can someone help me with Word Blanks?
Bill
@braunyb
Jan 31 2017 02:35

Can't get my text to output. Any help? thanks

function reuseFunction(){
console.log("Write Reusable JavaScript with Functions");
}
document.write(reuseFunction());

Kavita Kalaichelvan
@kkavita92
Jan 31 2017 02:37
'''
var code=x;
'''
CamperBot
@camperbot
Jan 31 2017 02:37
:bulb: to format code use backticks! ``` more info
Kavita Kalaichelvan
@kkavita92
Jan 31 2017 02:38
var code=x;
Margaret
@Margaret2
Jan 31 2017 02:40
@braunyb try calling your function: reuseFunction();
Carolina
@carodelafuente
Jan 31 2017 02:42
hello. Can someone help me with something very basic? I just can't seem to get it.
I have to program this using escape sequences:
FirstLine
\SecondLine\
ThirdLine

This is what I'm doing and:

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

Felix Blaquiere
@yulprojects
Jan 31 2017 02:44
@ronlaniado all you have to do is to change the var "result " by adding strings in between all the other var input
Christopher McCormack
@cmccormack
Jan 31 2017 02:45
@carodelafuente why are you adding ' characters?
Carolina
@carodelafuente
Jan 31 2017 02:48
@cmccormack without the quotes it's completely wrong for some reason. I assumed so the backlash could show I should probably quote it
Dorina
@dorinaaaaalin
Jan 31 2017 02:48
Hello. Can someone help me with javascript?

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

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

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

Christopher McCormack
@cmccormack
Jan 31 2017 02:49
@carodelafuente if you want to show a backslash, you just have to escape it. \\
Dorina
@dorinaaaaalin
Jan 31 2017 02:49
checkObj("gift") should return "pony".
checkObj("pet") should return "kitten".
João Mhurilo Godoi da Silva
@ebak123
Jan 31 2017 02:50
Guys, good night, listen, the lesson 276 is with a bug? The own exercise pass as argument 3 arrows, but the lesson give's a function with only one arrow as argument, so, if i return the same argument passed by the exercise, shows only the first arrow, rather then all of them...
Christopher McCormack
@cmccormack
Jan 31 2017 02:50
@dorinaaaaalin your argument for the hasOwnProperty should be the argument that was passed to your function, not a string
monkeyfingerz
@monkeyfingerz
Jan 31 2017 02:50

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
var c= celsius;
var fahrenheit= c*9/5=22;
// Only change code above this line
return fahrenheit;
}

// Change the inputs below to test your code
convertToF(30);

please help with answer
Carolina
@carodelafuente
Jan 31 2017 02:52
@monkeyfingerz I think you have to add 22 not equal 22
Christopher McCormack
@cmccormack
Jan 31 2017 02:52
should be 32 also
Kevin Manley
@akaBigCat
Jan 31 2017 02:53
for the Build a Random Quote Machine task I can't for the life of me get either jsonp or ajax to work, and im not sure what I'm doing wrong
Christopher McCormack
@cmccormack
Jan 31 2017 02:53
@akaBigCat That one can be rough if you're using mixed http/https elements
Kevin Manley
@akaBigCat
Jan 31 2017 02:54
looks like they should both be http
here is my pen
Christopher McCormack
@cmccormack
Jan 31 2017 02:54
@akaBigCat Make sure your quote API and your location API are either one or the other, and make sure if you are using codepen that codepen is also using the same protocol (it supports both by changing the URL)
Kevin Manley
@akaBigCat
Jan 31 2017 02:54
its a little messed up cause ive been testing out so many things
monkeyfingerz
@monkeyfingerz
Jan 31 2017 02:55
@carodelafuente its still wrong :(
Kevin Manley
@akaBigCat
Jan 31 2017 02:55
what do you mean are either one or the other?
do you mean http or https?
Bill
@braunyb
Jan 31 2017 02:56
image.png
Kevin Manley
@akaBigCat
Jan 31 2017 02:56
and also what is the location API for that one?
Bill
@braunyb
Jan 31 2017 02:57
I can't get the above code to work
Kevin Manley
@akaBigCat
Jan 31 2017 02:57
I've been trying to use the http://forismatic.com/en/api/ API
Carolina
@carodelafuente
Jan 31 2017 02:57
@monkeyfingerz i don't think you need a var for c, maybe try deleting that line and just leaving the var fahrenheit = c * 9/5 + 22
Christopher McCormack
@cmccormack
Jan 31 2017 02:58
@akaBigCat yeah http or https. Forget the lcoation, I was thinking of the weather project sorry
Philosopho
@Philosopho
Jan 31 2017 02:58

Hi! i'm at a loss to understanding what is wrong for the Where Do I Belong . this is my code: function getIndexToIns(arr, num) {
// Find my place in this sorted array.
arr.sort();
for(var i = 1; i < arr.length; i++){
if(arr[i-1] < num && arr[i] >= num)
return i;
if(arr[i-1] == num)
return i-1;

}
return arr.length;
}

Philosopho
@Philosopho
Jan 31 2017 02:59
For some reason it returns 1 for ([3, 10, 5], 3] should return 0
Kevin Manley
@akaBigCat
Jan 31 2017 02:59
thanks @cmccormack - and when you say using the same protocol, is that again http(s)?
CamperBot
@camperbot
Jan 31 2017 02:59
akabigcat sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 299 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Jan 31 2017 03:00
@akaBigCat yes that's what I'm referring to
Reggie
@Reggie01
Jan 31 2017 03:00
@akaBigCat You need to fix your syntax error. Also, you receive a promise back from your ajax call. You need to pass your callback function to .done() function.
.ajax().done(callback)
João Mhurilo Godoi da Silva
@ebak123
Jan 31 2017 03:00
Guys, good night, listen, the lesson 276 is with a bug? The own exercise pass as argument 3 arrows, but the lesson give's a function with only one arrow as argument, so, if i return the same argument passed by the exercise, shows only the first arrow, rather then all of them...
Kevin Manley
@akaBigCat
Jan 31 2017 03:01
thanks I'll look inot the .done() I didn't see that in any of the examples before
Philosopho
@Philosopho
Jan 31 2017 03:02
is the compiler reading arr[i-1] < num as not less than but less than and equal to? so should I report a bug?
Carolina
@carodelafuente
Jan 31 2017 03:02

@monkeyfingerz My bad, you do need to define c. I just ran this code and it worked fine:
function convertToF(celsius) {
var fahrenheit;

var c = celsius
var fahrenheit= c * 9/5 + 22;

return fahrenheit;
}

convertToF(30)

Manish Giri
@Manish-Giri
Jan 31 2017 03:04
using a separate variable c is not completely necessary
Reggie
@Reggie01
Jan 31 2017 03:04
@akaBigCat jquery ajax docs look under The jqXHR Object subheading.
Matt K
@MattKim22
Jan 31 2017 03:08
So I'm trying to build a random quote machine, but the idea I have doesn't have an API. I'm trying to make a random sports quote generator, and have inserted the quotes into separate arrays based on the sport. But, of course, now I'm stuck. Trying to figure out any way to get this to work. Any help would be appreciated
Manish Giri
@Manish-Giri
Jan 31 2017 03:08
@MattKim22 how would you decide which sport to pick from?
Matt K
@MattKim22
Jan 31 2017 03:08
it would be completely random
Manish Giri
@Manish-Giri
Jan 31 2017 03:08
okay
so what's the problem
pick a sport randomly
Matt K
@MattKim22
Jan 31 2017 03:09
i don't even know where to start, honestly
Manish Giri
@Manish-Giri
Jan 31 2017 03:09
show your pen?
wait never mind
first, pick a random sport
//types of sports
var sports = ["tennis", "football", "soccer"...];
var pickedSport = /* a random sport from sports array */;
João Mhurilo Godoi da Silva
@ebak123
Jan 31 2017 03:11
No one can help?
Manish Giri
@Manish-Giri
Jan 31 2017 03:11
i'm guessing you'd have further arrays like this
var tennisQuotes = [...];
var footballQuotes = [...];
Matt K
@MattKim22
Jan 31 2017 03:11
exactly
those are basically all i have at this point
Manish Giri
@Manish-Giri
Jan 31 2017 03:11
use a switch on pickedSport
for case "tennis": quote = /* random quote from tennisQuotes array */
and so on
that's all there is.
João Mhurilo Godoi da Silva
@ebak123
Jan 31 2017 03:13
Guys, theres a issue with exercise 276? The passed arguments are 3 or more arrays, but, the function only receive one argument, so i can't access all the arguments, or generalize the exercise... What do i do?
Manish Giri
@Manish-Giri
Jan 31 2017 03:14
@ebak123 what's the challenge name?
João Mhurilo Godoi da Silva
@ebak123
Jan 31 2017 03:14
Sorted Union
Manish Giri
@Manish-Giri
Jan 31 2017 03:15
@ebak123 have you used the arguments object?
João Mhurilo Godoi da Silva
@ebak123
Jan 31 2017 03:15
there is like something(1,2,[3]); but, should be something([1,2,[3]]);
ops, all worng haha
i tried, but i wanna access all the arrays, and i cant like this, in normal way
Manish Giri
@Manish-Giri
Jan 31 2017 03:17
you can access all of them with arguments.
Deetss
@Deetss
Jan 31 2017 03:25
hey is there anyway to keep a function from running multiple times until the current function is finished?
Skullvapor
@Skullvapor
Jan 31 2017 03:27
I don't get what is Stand In Line asking us to do?
Manish Giri
@Manish-Giri
Jan 31 2017 03:32
@Skullvapor okay, your function gets two arguments - arr and item, yes?
Skullvapor
@Skullvapor
Jan 31 2017 03:33
yes.
Manish Giri
@Manish-Giri
Jan 31 2017 03:34
the first step is to add the number itemto the end of the array arr, use .push() for this.
the second and final step is to remove and return the first element from the array arr, use .shift()for this.
Reggie
@Reggie01
Jan 31 2017 03:34
@Deetss can you show a code example of what your trying to do or give more details
Deetss
@Deetss
Jan 31 2017 03:35
@Deetss
so im working on an image slider and when you click the button to change slides it will take as many inputs as you give it before it transitions
but i want it to finish the transition before it moves to another slide

```function prev(){
newSlide = sliderInt-1;
showSlide(newSlide);
};

function next(){
newSlide = sliderInt+1;
showSlide(newSlide);

};

Skullvapor
@Skullvapor
Jan 31 2017 03:35
@Manish-Giri I didn't read that Arr was an array :.)
Deetss
@Deetss
Jan 31 2017 03:36
function prev(){
newSlide = sliderInt-1;
showSlide(newSlide);
};
function next(){
newSlide = sliderInt+1;
showSlide(newSlide);
};
Manish Giri
@Manish-Giri
Jan 31 2017 03:36
@Skullvapor well now you know!
Julius Robinson
@Julius-R
Jan 31 2017 03:43
How do I get this to take the name from the prompt and replace a div element?

var name = prompt('Hello, what is your name?');

('Thank you for visiting, ' + name);

Reggie
@Reggie01
Jan 31 2017 03:47

@Deetss hmm, my guess is that your going to have to give your image slider some type of state.

  state: { inTransition: boolean }

That way a person can't queue up a transition until the current transition finishes. I guess something like

state.inTransition = false;
function prev() {
  if( !state.inTransition ) {
    state.inTransition = True;
    showSlide( newSlide );
  }
}
showSlide( newSlide ) {
  // your current code
 state.inTransition = False;
}
Deetss
@Deetss
Jan 31 2017 03:49
@Julius-R try using replaceWith
Julius Robinson
@Julius-R
Jan 31 2017 03:50
@Deetss
var name = prompt('Hello, what is your name?'); 


function() {
    #welcome.document.innerHTMl('Thank you for visiting, ' + name);     
};


<div id="welcome"><h1>Thank You For Visiting!</h1></div>
I didn't post it correct the first time. This is the full code. I want the text to change ad add user's name at the end.
Deetss
@Deetss
Jan 31 2017 03:59
var visiting = function(name) {
    $('#welcome>h1').replaceWith('Thank you for visiting, ' + name);  
};

var name = prompt('Hello, what is your name?'); 
visiting(name);
i think this may be kinda what youre looking for
Julius Robinson
@Julius-R
Jan 31 2017 04:00
Yes!
What is the $ ?
Deetss
@Deetss
Jan 31 2017 04:01
its jquery's version of document.getelement
so you could put document.getelementbyid
that would be the equivalent in javascript
Julius Robinson
@Julius-R
Jan 31 2017 04:03
oh!
How do I add css to it? I have a black background and was using a text color
ANormalSoundingName
@ANormalSoundingName
Jan 31 2017 04:09
hi, I'm getting an infinite loop, but I'm not sure what's causing it
Deetss
@Deetss
Jan 31 2017 04:09
is it not working with your background?
sorry. how do I get that box?
Keli Fine
@kelifine
Jan 31 2017 04:11
Hey everyone, I'm trying to build the wikipedia viewer but for some reason my JSON is not working, either that or the way I'm trying to call the data is wrong. Can anyone help? I'm using https://codepen.io
$(document).ready(function() {
  var input = $("#wikisearch").val();
  $("button").onclick(function(input) {
    var link = "https://en.wikipedia.org//w/api.php?action=query&format=json&prop=extracts&continue=%7C%7C&generator=allpages&exsentences=10&explaintext=1&excontinue=4&gapfrom=" + $(input) + "&gaplimit=5";
  });
  $.getJSON(link, function(query) {
    var arr1 = [];
    for (var i = 0; i < query.length; i++) {
      arr1.push(query.pages)
    };

    $("#first").html(query.pages.arr1[0].title);
  });

});
Deetss
@Deetss
Jan 31 2017 04:12
@ANormalSoundingName check your for loop, looks out of order to me
ANormalSoundingName
@ANormalSoundingName
Jan 31 2017 04:12
@kelifine how do you link your code in that box?
Deetss
@Deetss
Jan 31 2017 04:12
put " ```"
no quotes
ANormalSoundingName
@ANormalSoundingName
Jan 31 2017 04:13

```function factorialize(num) {

var produce = 1; //used to hold the final value of 'num', so 'num' can be used in the for loop

for(var i = 2;i++;i <= num){ //I don't see how this is infinite, since 'num' = 5, and the loop stops when 'i' is no longer less than, or equal to 'num'
var farmism = (produce * i); //creates variable to hold the new value of 'produce'
produce = farmism; //assigns the value of 'farmism' to 'produce'
} //none of these steps change the value of 'i', so what could be causing an infinite loop?

return produce;
}

factorialize(5);```

?
Keli Fine
@kelifine
Jan 31 2017 04:14
@ANormalSoundingName the ``` needs to be on a separate line
Deetss
@Deetss
Jan 31 2017 04:15
@ANormalSoundingName check your for loop its out of order, youre not comparing i before you add to it
ANormalSoundingName
@ANormalSoundingName
Jan 31 2017 04:15
function factorialize(num) {

  var produce = 1; //used to hold the final value of 'num', so 'num' can be used in the for loop

  for(var i = 2;i++;i <= num){ //I don't see how this is infinite, since 'num' = 5, and the loop stops when 'i' is no longer less than, or equal to 'num'
    var farmism = (produce * i); //creates variable to hold the new value of 'produce'
    produce = farmism; //assigns the value of 'farmism' to 'produce'
  } //none of these steps change the value of 'i', so what could be causing an infinite loop?

  return produce;
}

factorialize(5);
thanks for the box
@Deetss What do you mean comparing?
Keli Fine
@kelifine
Jan 31 2017 04:16
no problem
ANormalSoundingName
@ANormalSoundingName
Jan 31 2017 04:17
@Deetss on the farmism line?
Keli Fine
@kelifine
Jan 31 2017 04:17
@ANormalSoundingName for loops should have the format (initiating condition, ending condition, increment)
Deetss
@Deetss
Jan 31 2017 04:17
so your for statement is setting i = 2 then its just adding, its not checking what i is set to
ANormalSoundingName
@ANormalSoundingName
Jan 31 2017 04:19
@kelifine @Deetss omg how have I mae it this far? thanks I've been struggling for days
CamperBot
@camperbot
Jan 31 2017 04:19
anormalsoundingname sends brownie points to @kelifine and @deetss :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for deetss
:cookie: 297 | @kelifine |http://www.freecodecamp.com/kelifine
ANormalSoundingName
@ANormalSoundingName
Jan 31 2017 04:19
that solved it
archivum
@archivum
Jan 31 2017 04:20
Hi everyone
Does anyone know why the 'longest' variable gets assigned the longest string in this situation?

var arr = ['first item', 'second item is longer than the third one', 'third longish item'];

var lgth = 0;
var longest;

for(var i=0; i < arr.length; i++){
if(arr[i].length > lgth){
var lgth = arr[i].length;
longest = arr[i];
}
}

alert(longest);

mrimosthe1
@mrimosthe1
Jan 31 2017 04:21
hey guys in the chapter nesting for loops I need some help
the code
```

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*=multiplyAll[j];
    }
     product*=multiplyAll[i];
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Manish Giri
@Manish-Giri
Jan 31 2017 04:22
@spyte3n in this array - [[1,2],[3,4],[5,6,7]]
how would you access the number 3?
mrimosthe1
@mrimosthe1
Jan 31 2017 04:23
uhm
Keli Fine
@kelifine
Jan 31 2017 04:23
@archivum the for loop iterates over each item in the array, if the item is longer than the previous longest item then it gets saved to the longest variable, so it'll stop changing longest one there are no more items that are longer in it in the array. if that made sense.
mrimosthe1
@mrimosthe1
Jan 31 2017 04:23
I need to add another loop then?
@Manish-Giri
Manish Giri
@Manish-Giri
Jan 31 2017 04:24
@spyte3n no, forget the loops for a minute. How would you access the number 3, using the variable arr-
var arr = [[1,2],[3,4],[5,6,7]];
mrimosthe1
@mrimosthe1
Jan 31 2017 04:26
arr2?
```arr2
```
arr[2][2]
?
Joe Escobedo
@joeEscob1023
Jan 31 2017 04:26
what does iterate through an array mean?
Keli Fine
@kelifine
Jan 31 2017 04:27
go through each item
mrimosthe1
@mrimosthe1
Jan 31 2017 04:27
@Manish-Giri
Manish Giri
@Manish-Giri
Jan 31 2017 04:27
@spyte3n not quite, array indices begin at 0
archivum
@archivum
Jan 31 2017 04:27
@kelifine thank you! That makes sense.
CamperBot
@camperbot
Jan 31 2017 04:27
archivum sends brownie points to @kelifine :sparkles: :thumbsup: :sparkles:
:cookie: 298 | @kelifine |http://www.freecodecamp.com/kelifine
Manish Giri
@Manish-Giri
Jan 31 2017 04:27
so arr[0] is [1,2]
and arr[0][1] is the number 2.
mrimosthe1
@mrimosthe1
Jan 31 2017 04:27
yes
Manish Giri
@Manish-Giri
Jan 31 2017 04:27
@spyte3n
so what is 3?
mrimosthe1
@mrimosthe1
Jan 31 2017 04:29
```arr[3]
```
arr[3]
right? @Manish-Giri
Manish Giri
@Manish-Giri
Jan 31 2017 04:29
arr[3] doesn't even exist.
mrimosthe1
@mrimosthe1
Jan 31 2017 04:30
sorry
2
Manish Giri
@Manish-Giri
Jan 31 2017 04:30
arr[0] is [1,2]
mrimosthe1
@mrimosthe1
Jan 31 2017 04:30
arr[2]
Manish Giri
@Manish-Giri
Jan 31 2017 04:30
arr[1] is [3,4]
and arr[2] is [5,6,7]
mrimosthe1
@mrimosthe1
Jan 31 2017 04:31
yes
Manish Giri
@Manish-Giri
Jan 31 2017 04:31
so, how would you get the number 3?
remember, arr[1] is itself an array - [3,4]
so you need another index to access an element from it.
mrimosthe1
@mrimosthe1
Jan 31 2017 04:32
arr[1][0]
I thiught you were asking for the third one
now?
Manish Giri
@Manish-Giri
Jan 31 2017 04:34
correct
so my point is - since arr is a 2-dimensional array, you need two indices to access a particular number.
Guess that's clear?
mrimosthe1
@mrimosthe1
Jan 31 2017 04:34
yes
I did that earlier
```
Manish Giri
@Manish-Giri
Jan 31 2017 04:35
so, from what you learnt now, what do you need to fix here -
product*=multiplyAll[j];
mrimosthe1
@mrimosthe1
Jan 31 2017 04:35

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*=multiplyAll[i][j];
    }

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

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Manish Giri
@Manish-Giri
Jan 31 2017 04:35
well there you have it
mrimosthe1
@mrimosthe1
Jan 31 2017 04:35
the error shows null
Manish Giri
@Manish-Giri
Jan 31 2017 04:35
multiplyAll[i][j];
what is the name of the array?
mrimosthe1
@mrimosthe1
Jan 31 2017 04:36
Shit
man what a mess
it should be arr
Manish Giri
@Manish-Giri
Jan 31 2017 04:36
yes
mrimosthe1
@mrimosthe1
Jan 31 2017 04:37
Thanks for having the patience @Manish-Giri I reaaly appreciate it
CamperBot
@camperbot
Jan 31 2017 04:37
spyte3n sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 4015 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Jan 31 2017 04:37
@spyte3n welcome!
Deetss
@Deetss
Jan 31 2017 04:44

@Reggie01 hey i tried

state.inTransition = false;
function prev() {
  if( !state.inTransition ) {
    state.inTransition = True;
    showSlide( newSlide );
  }
}
showSlide( newSlide ) {
  // your current code
 state.inTransition = False;
}

and it didnt seem to work

Reggie
@Reggie01
Jan 31 2017 04:50
@Deetss ok, did you wrap the next function logic in the same conditional?
function next() {
  if(!state.inTransition ) {
    state.inTransition = false;
   showSlide( newSlide );
 }
}
Nathanael-M
@Nathanael-M
Jan 31 2017 04:51
I am at a complete loss over the Mutations challenge. Any hints?
Joe Escobedo
@joeEscob1023
Jan 31 2017 04:51

var array = [4,5,6,7,8];
var singleVal = 0;

// Only change code below this line.

singleVal = array.reduce(function(prevVal, currVal){
return prevVal + currVal;
});

30

how do i get 30 out of this?
Deetss
@Deetss
Jan 31 2017 04:51
@Reggie01 yes i did, idk whats going wrong
OuRyoShin
@DJQTDJ
Jan 31 2017 04:52
@Nathanael-M
thanks for cured my cervical spondylosis
CamperBot
@camperbot
Jan 31 2017 04:52
djqtdj sends brownie points to @nathanael-m :sparkles: :thumbsup: :sparkles:
:cookie: 252 | @nathanael-m |http://www.freecodecamp.com/nathanael-m
Nathanael-M
@Nathanael-M
Jan 31 2017 04:53
Somedays you wake up unemployed and go to bed a doctor.
Reggie
@Reggie01
Jan 31 2017 04:55
@Deetss are you getting a reference Error? true and false has to be lowercase
@Nathanael-M An unemployed doctor?
Cristopher Encarnacion
@chris0715
Jan 31 2017 04:57
Need a hand understanding something with ReactJS
Manish Giri
@Manish-Giri
Jan 31 2017 04:57
@TacoJoe it already returns 30
Reggie
@Reggie01
Jan 31 2017 04:57
@Nathanael-M This sounds like graduation.
Deetss
@Deetss
Jan 31 2017 05:00
@Reggie01 i keep getting a reference Error for the state : {inTransition: boolean}
Reggie
@Reggie01
Jan 31 2017 05:01
@Deetss yeah, true and false both have to be lowercase
Siddhartha Sehgal
@okaysidd
Jan 31 2017 05:02
The projects given for reference for us to make, eg, Portfolio Page, Random Quote generator, etc. all use SCSS, not taught yet. Do we have to learn it on our own and make the projects? Because otherwise the projects turn out to be really bland.
Deetss
@Deetss
Jan 31 2017 05:02
@Reggie01 its when im declaring state before i ever get into my function
Manish Giri
@Manish-Giri
Jan 31 2017 05:02
@okaysidd you can use regular css instead of scss
using scss is not a requirement
there's a reason why they say "don't look at the example code"
Siddhartha Sehgal
@okaysidd
Jan 31 2017 05:03
But then the webpages come out to be really simple and not, you know, website-ready-presentable.
Manish Giri
@Manish-Giri
Jan 31 2017 05:03
huh?
Deetss
@Deetss
Jan 31 2017 05:03
@Reggie01
state: {inTransition : boolean}
state.inTransition = false;
function prev(){
  if( !state.inTransition ) {
    state.inTransition = true;
    newSlide =  sliderInt-1;
    showSlide(newSlide);
  }
};
Manish Giri
@Manish-Giri
Jan 31 2017 05:03
css has the same effect as scss @okaysidd
it's just the syntax that is different
Reggie
@Reggie01
Jan 31 2017 05:04

@Deetss

var state = {};
state.inTransition = false;

You don't have to create an object

var sliderInTransition = false;
Siddhartha Sehgal
@okaysidd
Jan 31 2017 05:04
I might have to go deeper into CSS then.
Thank you anyway @Manish-Giri
CamperBot
@camperbot
Jan 31 2017 05:04
okaysidd sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 4016 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Jan 31 2017 05:04

like

.header {
color: red;
}

.header h1 {
text-decoration: underline;
}

this is CSS

@okaysidd
the same thing written in SCSS will be
.header {
color: red; 
   h1 {
       text-decoration: underline;
    }
}
same result, different syntax
Siddhartha Sehgal
@okaysidd
Jan 31 2017 05:06
We can do the beautiful animations with CSS? @Manish-Giri
Manish Giri
@Manish-Giri
Jan 31 2017 05:06
yes
Siddhartha Sehgal
@okaysidd
Jan 31 2017 05:06
I'll look into it
Deetss
@Deetss
Jan 31 2017 05:12
@Reggie01 okay i tried that still nothing, im sure its just how i have everything set up
Reggie
@Reggie01
Jan 31 2017 05:15
@Deetss I probably don't fully understand your problem. Are your transitions through code or css?
Deetss
@Deetss
Jan 31 2017 05:21
@Reggie01 when you click the button it calls a the prev() or next() function <a href="#" class="left" onclick="prev();">Previous</a>
Reggie
@Reggie01
Jan 31 2017 05:22
@Deetss can you show your showSlide function
Deetss
@Deetss
Jan 31 2017 05:23
function showSlide(id){
  stopLoop();
  if(id>count){
    id = 1;
  }else if(id<1){
    id=count;
  }
  $("#slider>img").hide();
  $("#slider>img#img" + id).show();


  id = sliderNext;
  sliderNext = id + 1;
  inTransition = false;
  startSlider();
}
Giovanni Massimiliano
@jovimassimiliano
Jan 31 2017 05:28

hello guys, i’m currently on fcc's local weather project. I’m kinda exhausted, because my ajax not working in codepen while in my local host working good. Can anyone help me?

here’s my codepen link: https://codepen.io/jovimassimiliano/pen/pRWEoK

Reggie
@Reggie01
Jan 31 2017 05:41
@Deetss ok i'll pm you
Joseph
@revisualize
Jan 31 2017 05:49
Hi.
Andy
@AndyRSV
Jan 31 2017 05:50
Hi everyone! Im kinda stuck for a reason that I cannot understand on the challenge #208 on basic JS

var count = 0;

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

  if (card  == 2|| card  == 3|| card  == 4|| card  == 5|| card  == 6){
    count += 1;

   }

  else if (card  == 7|| card  == 8|| card  == 9){
     count += 0;

   }

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


  if (count > 0){
     return count + " Bet";
  }
  else if (count < 0){
    return count + " Hold";
  }


  // 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');
mrimosthe1
@mrimosthe1
Jan 31 2017 05:51
@AndyRSV use switch case it will be much simpler
and that is the objective too I gues of that excercise
Manish Giri
@Manish-Giri
Jan 31 2017 05:52
@AndyRSV you're missing out on the case when count == 0
 if (count > 0){
     return count + " Bet";
  }
  else if (count < 0){
    return count + " Hold";
  }
modify the second else if to account for <= 0
AudioGen
@AudioGen
Jan 31 2017 05:53
I'm having issues with one of the challenges
Anyone around want to try and help?
Eric
@ericsolomon21
Jan 31 2017 05:58
Hey guys, Im working on the twitch.tv app and I am having a jQuery issue I think. I am trying to run a jQuery function through a loop and it isn't working. I have console.log(streamUrl); before the jQuery function and it is looping through the array fine, but when I put console.log(streamUrl); after the jQuery function, it calls the last string in the array each time....any Ideas?
for (var j = 0; j < tvChannels.length; j++){
   var streamUrl = "https://api.twitch.tv/kraken/streams/" + tvChannels[j] +"?client_id=5m1f6u3xqnrk5ucsc03tesyq11clj9"
   var userUrl = "https://api.twitch.tv/kraken/users/" + tvChannels[j] +"?client_id=5m1f6u3xqnrk5ucsc03tesyq11clj9"
    console.log(streamUrl);
  $.getJSON(streamUrl, function(data0) {
    console.log(streamUrl);
Manish Giri
@Manish-Giri
Jan 31 2017 05:58
@AudioGen which challenge
AudioGen
@AudioGen
Jan 31 2017 05:59
@Manish-Giri Make a Person
Manish Giri
@Manish-Giri
Jan 31 2017 05:59
@AudioGen okay, shoot
AudioGen
@AudioGen
Jan 31 2017 05:59
I'm not able to copy and paste, so I might have to rewrite it all here
Manish Giri
@Manish-Giri
Jan 31 2017 06:00
why can't you copy paste?
AudioGen
@AudioGen
Jan 31 2017 06:00
I dunno
Manish Giri
@Manish-Giri
Jan 31 2017 06:00
post a screenshot then
AudioGen
@AudioGen
Jan 31 2017 06:00
Yah that's what I was thinking too
Sahil Sunny
@sahilsunny
Jan 31 2017 06:00
symmetric difference challenge not working
function sym(args) {
  args = [];

  for(var ar = 0; ar < arguments.length; ar++) {
    args.push(arguments[ar]); //pushing all the arguments into args
  }
  function symDiff(arrayOne, arrayTwo) {
    var result = [];

    arrayOne.forEach(function(item) {
      if(arrayTwo.indexOf(item) < 0 && result.indexOf(item) < 0) {
        result.push(item);// if item not in array two and result
      }
    });

    arrayTwo.forEach(function(item) {
      if(arrayOne.indexOf(item) < 0 && result.indexOf(item) < 0) {
        result.push(item);// if item not in array one and result
      }
    });
    return result;
  }
  return args.reduce(symDiff);
}

sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]);
am getting the result but still its showing crosses on all
@Manish-Giri It's satisfying all the conditions for "Bob Ross" but when it sets the name to "Haskell Curry" it's not accepting it
Manish Giri
@Manish-Giri
Jan 31 2017 06:04
@AudioGen look at your setFullName function..
AudioGen
@AudioGen
Jan 31 2017 06:10
@Manish-Giri What about it? I've tried removing the parameter as it's declared in the constructor function but it doesn't change anything
David
@DavidGcastro
Jan 31 2017 06:12
hey guys
can someone please explain to me why this works? I cant seem to get my head around it var arr = [
[1,2], [3,4], [5,6]
];
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}
does the first loop take care of the big function nesting the 3?
this is number 214 btw
Lawanu Borthakur
@Lawanu
Jan 31 2017 06:14
how to send screenshot of codes?
David
@DavidGcastro
Jan 31 2017 06:15
haaalppp
AudioGen
@AudioGen
Jan 31 2017 06:15
@DavidGcastro Yah first loop takes care of the 3
Pallavi Goyal
@pallavi-goyal
Jan 31 2017 06:16

Hello all,

I am working on Roman Numerals challenge.
The problem is, for every check, the value is overriding. Ex: For 1900, its giving CM as output instead of MCM. Please tell me where I am going wrong.

Thanks in advance.
function convertToRoman(num) {
var temp1 = num / 1000;
var result = [];

//For thousands
var string1 = "";
if (temp1 == 3) {
result.push("MMM");
} if (temp1 == 2) {
result.push("MM");
} if (temp1 == 1) {
result.push("M");
}
result.push(string1);
//For hundreds
var temp2 = num % 1000;
var temp3 = temp2 / 100;
var string2 = "";
if (temp3 == 9) {
result.push("CM");
} if (temp3 == 8) {
result.push("DCCC");
} if (temp3 == 7) {
result.push("DCC");
} if (temp3 == 6) {
result.push("DC");
} if (temp3 == 5) {
result.push("D");
} if (temp3 == 4) {
result.push("CD");
} if (temp3 == 3) {
result.push("CCC");
} if (temp3 == 2) {
result.push("CC");
} if (temp3 == 1) {
result.push("C");
}
result.push(string2);
//For tens
var temp4 = temp2 % 100;
var temp5 = temp4 / 10;

if (temp5 == 9) {
result.push("XC");
} if (temp5 == 8) {
result.push("LXXX");
} if (temp5 == 7) {
result.push("LXX");
} if (temp5 == 6) {
result.push("LX");
} if (temp5 == 5) {
result.push("L");
} if (temp5 == 4) {
result.push("XL");
} if (temp5 == 3) {
result.push("XXX");
} if (temp5 == 2) {
result.push("XX");
} if (temp5 == 1) {
result.push("X");
}

return result.join('');
}

convertToRoman(1950);

Manish Giri
@Manish-Giri
Jan 31 2017 06:16
@AudioGen bob.setFullName("Haskell Curry") - here, firstAndLast is Haskell Curry
Yomiyu
@yomiyu
Jan 31 2017 06:16
would anyone be able to help me with "Escape Sequences in Strings"
Manish Giri
@Manish-Giri
Jan 31 2017 06:16
but then I don't see any code where you change the first and last variables to match the new names.
David
@DavidGcastro
Jan 31 2017 06:17
@AudioGen how? I just need a step by step
Yomiyu
@yomiyu
Jan 31 2017 06:17
I'm not sure what they're trying to ask
David
@DavidGcastro
Jan 31 2017 06:17
how does the loop skip the first array
Lawanu Borthakur
@Lawanu
Jan 31 2017 06:17
@AudioGen how to send screenshot of codes?
David
@DavidGcastro
Jan 31 2017 06:17
var arr = [
[1,2], [3,4], [5,6]
];
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}
if some one can explain the path of this loop for me
AudioGen
@AudioGen
Jan 31 2017 06:18
@DavidGcastro Hold on, Manish is trying to help me with a problem
David
@DavidGcastro
Jan 31 2017 06:18
@AudioGen ok bro
Manish Giri
@Manish-Giri
Jan 31 2017 06:18
@DavidGcastro okay, so this loop - for (var i=0; i < arr.length; i++) { goes through the outermost array -
[
[1,2], [3,4], [5,6]
];
AudioGen
@AudioGen
Jan 31 2017 06:19
@Manish-Giri I declare the first and last variables at the beginning of the constructor and it's not specific to any name, it's sliced at the whitespace, so I don't see why it wouldn't accept it?
Manish Giri
@Manish-Giri
Jan 31 2017 06:19
I mean - arr[0] will be [1,2], and arr[1] will be [3,4] and arr[2] will be [5,6]
@DavidGcastro
AudioGen
@AudioGen
Jan 31 2017 06:19
@Manish-Giri I've actually ran it on a separate JSconsole program and I pretty much tried all the conditions and it works
GauravChandrawale
@GauravChandrawale
Jan 31 2017 06:20
Return Early Pattern for Functions ..... plz help with this lesson
hav no idea wt to do
Manish Giri
@Manish-Giri
Jan 31 2017 06:20
@AudioGen copy your code in here - https://jsbin.com/
and share the link
David
@DavidGcastro
Jan 31 2017 06:21
@Manish-Giri now i get it
Markus Kiili
@Masd925
Jan 31 2017 06:21
@pallavi-goyal It is a better idea to put the letters and numbers (basis of Roman numerals) on arrays first. Then solve it by iterating the array of numbers.
Manish Giri
@Manish-Giri
Jan 31 2017 06:21
@DavidGcastro and this loop - for (var j=0; j < arr[i].length; j++) {
runs for each value of the i
David
@DavidGcastro
Jan 31 2017 06:21
in the bigger array the smaller arrays are just indexs, going by 1,2,3
so the first loop runs 3 times
then
the smaller one does
what lol
Manish Giri
@Manish-Giri
Jan 31 2017 06:23

in the bigger array the smaller arrays are just indexs, going by 1,2,3

not 1,2,3 rather 0, 1,2

David
@DavidGcastro
Jan 31 2017 06:23
yes exactlty
so then
AudioGen
@AudioGen
Jan 31 2017 06:23
@Manish-Giri ok
Manish Giri
@Manish-Giri
Jan 31 2017 06:23
then when i is 0, j runs from 0 to 1, because length of arr[0] is 2.
David
@DavidGcastro
Jan 31 2017 06:24
@Manish-Giri I have a question. does the first loop run 3 time and stops
Manish Giri
@Manish-Giri
Jan 31 2017 06:24
arr[0] is [1,2], so when j = 0, arr[0][0] is 1, and when j = 1, arr[0][1] is 2
David
@DavidGcastro
Jan 31 2017 06:25
are does it go right after the second
Manish Giri
@Manish-Giri
Jan 31 2017 06:25
yes, outer loop runs 3 times, from 0 to 2
Paul DiLoreto
@paulmichaelxd
Jan 31 2017 06:28
@GauravChandrawale what don’t you understand?
AudioGen
@AudioGen
Jan 31 2017 06:28
@Manish-Giri I don't really get what I'm doing here
@Manish-Giri what do you want me to link?
Is that right?
Manish Giri
@Manish-Giri
Jan 31 2017 06:29
yes
one sec
GauravChandrawale
@GauravChandrawale
Jan 31 2017 06:29
@paulmichaelxd how to code tht
n wt this line does .... "return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));"
Pallavi Goyal
@pallavi-goyal
Jan 31 2017 06:30
@Masd925 Thanks Markus, But can you tell me what is wrong here?
CamperBot
@camperbot
Jan 31 2017 06:30
pallavi-goyal sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 3264 | @masd925 |http://www.freecodecamp.com/masd925
AudioGen
@AudioGen
Jan 31 2017 06:31
@Manish-Giri You there Manish?
李文俊
@G21iwenjun
Jan 31 2017 06:31
seek to destroy 怎么做 谁有答案
AudioGen
@AudioGen
Jan 31 2017 06:31
@Manish-Giri See what I mean? I don't get it
Manish Giri
@Manish-Giri
Jan 31 2017 06:32
help
Manish Giri
@Manish-Giri
Jan 31 2017 06:32
see the print statements, you'll understand what I mean
@AudioGen
tanvircse777
@tanvircse777
Jan 31 2017 06:32
give me some hints
Lawanu Borthakur
@Lawanu
Jan 31 2017 06:32

can any help me with this code im not getting the proper output.Challenge:Repeat a string
~~~
function repeatStringNumTimes(str, num) {
// repeat after me
var s_arr=[],j=0;
s_arr=str.split('');
var length=s_arr.length;
for(var i=length;i<(length+length*num);i++)
{
s_arr[i]=s_arr[j];
j++;
}

return s_arr.join("");

}

repeatStringNumTimes("*",3);

Manish Giri
@Manish-Giri
Jan 31 2017 06:33

@AudioGen even after you change the full name -

bob.setFullName("Haskell Curry");

you still get the old name

"Bob"
"Ross"
"Bob Ross"
Paul DiLoreto
@paulmichaelxd
Jan 31 2017 06:33
@GauravChandrawale okay, well the whole point of this lesson is to get you to understand how a function takes parameters and can return a variable of any type
tanvircse777
@tanvircse777
Jan 31 2017 06:34
Can anyone help, please
Markus Kiili
@Masd925
Jan 31 2017 06:34
@pallavi-goyal There is something wrong with the checks. If num if for example 1950, num/1000 is 1.95. It is not equal to 1 or 2 or 3.
AudioGen
@AudioGen
Jan 31 2017 06:34
@Manish-Giri Ok, so when I'm doing it on mine, it works because I'm calling on the Constructor function again?
Markus Kiili
@Masd925
Jan 31 2017 06:35
@pallavi-goyal Maybe you need to use num/1000>>0 which gives how many times 1000 fits into num.
Manish Giri
@Manish-Giri
Jan 31 2017 06:35
@AudioGen I don't know what you mean by that, what code I have is literally what you gave me.
so Idk how it works in your case.
Paul DiLoreto
@paulmichaelxd
Jan 31 2017 06:36
@GauravChandrawale so the goal of the lesson is to get the function abTest return undefined… so instead of returning a variable, you return the keyword undefined, meaning no information is there
Deetss
@Deetss
Jan 31 2017 06:36
@tanvircse777 what are you having trouble wiht?
Manish Giri
@Manish-Giri
Jan 31 2017 06:36
@AudioGen unless you mean new Person()...
because you won't do that every time
AudioGen
@AudioGen
Jan 31 2017 06:37
Woops
Manish Giri
@Manish-Giri
Jan 31 2017 06:37
in the challenge - the constructor function is running only once(from what I remember)
AudioGen
@AudioGen
Jan 31 2017 06:37
Yah, I kind of get that now
Manish Giri
@Manish-Giri
Jan 31 2017 06:37
your object is created, and then you modify the first name and last name using getters/setters
Paul DiLoreto
@paulmichaelxd
Jan 31 2017 06:37
@GauravChandrawale so all you need to do is make an if statement testing whether the paramenters defined on line 3 a and b are < 0 (negative) then return undefined
Manish Giri
@Manish-Giri
Jan 31 2017 06:37
a new object isn't created again.
AudioGen
@AudioGen
Jan 31 2017 06:38
@Manish-Giri Not following why it's not setting though
Manish Giri
@Manish-Giri
Jan 31 2017 06:39
@AudioGen again, because this is wrong
this.setFullName = function(firstAndLast){fistAndLast = this.firstAndLast;};
this doesn't modify first and last in anyway
Paul DiLoreto
@paulmichaelxd
Jan 31 2017 06:40
@GauravChandrawale the last statement just calls upon the Math object, which is included in javascript, and uses the round function, which takes in a number with a decimal and rounds it to the nearest integer. Within the () is the pow function, which takes in 2 parameters and return the number that equals the first parameter to the power of the second parameter. The first parameter for pow is Math.sqrt(a) + Math.sqrt(b)… which takes those parameters given in line 3 and returns the square root of a plus the square root of be.
Manish Giri
@Manish-Giri
Jan 31 2017 06:41
@AudioGen not only that, your order of assignment is wrong, there's no property called this.firstAndLast
 this.setFullName = function(firstAndLast){
    console.log("this.firstAndLast = " + this.firstAndLast); //undefined
    fistAndLast = this.firstAndLast;};
Lawanu Borthakur
@Lawanu
Jan 31 2017 06:42
///
GauravChandrawale
@GauravChandrawale
Jan 31 2017 06:42
@paulmichaelxd heyy thtx .... test cleared .... thnks ..it help me a lott
Paul DiLoreto
@paulmichaelxd
Jan 31 2017 06:42
@GauravChandrawale As a result, the sum of these to square roots is passed on to Math.pow(base second exponent - which is 2). That is then rounded.
@GauravChandrawale hope you understood the point of the lesson! not just how to solve it
@GauravChandrawale :D
OuRyoShin
@DJQTDJ
Jan 31 2017 06:43
how to solve this?
Refused to load the image 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA8Q1JFQVRPUjogZ2QtanBl…N+7+4n2O3www58sZc5bP0f8A/jpJ4LvLTwf4suvN8H3U/+gX83/Mt3Fxd/h/xJfb+XcooA/9k=' because it violates the following Content Security Policy directive: "default-src 'self' 'unsafe-eval' 'unsafe-inline'". Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.


Refused to load the image 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA8Q1JFQVRPUjogZ2QtanBl…N+7+4n2O3www58sZc5bP0f8A/jpJ4LvLTwf4suvN8H3U/+gX83/Mt3Fxd/h/xJfb+XcooA/9k=' because it violates the following Content Security Policy directive: "img-src * ".
Paul DiLoreto
@paulmichaelxd
Jan 31 2017 06:44

Hey guys! Does anyone have any idea why my jQuery code isn’t working in a mobile view? If you take my codepen and go to developer view in mobile mode, the jQuery stops working. Any idea why?

http://codepen.io/paulmichaelxd/pen/xgPBaz

Lawanu Borthakur
@Lawanu
Jan 31 2017 06:45

///
function repeatStringNumTimes(str, num) {
// repeat after me
var s_arr=[],j=0;
s_arr=str.split('');
var length=s_arr.length;
for(var i=length;i<(length+length*num);i++)
{
s_arr[i]=s_arr[j];
j++;
}

return s_arr.join("");

}

repeatStringNumTimes("*",3);

GauravChandrawale
@GauravChandrawale
Jan 31 2017 06:45
@paulmichaelxd yess i understood .... solved prb is thr .. bt i dnt understand it
thnk u
Paul DiLoreto
@paulmichaelxd
Jan 31 2017 06:46
@GauravChandrawale no problem
GauravChandrawale
@GauravChandrawale
Jan 31 2017 06:47
ur all explaination i put in my code as a comment @paulmichaelxd .... :smile:
Pallavi Goyal
@pallavi-goyal
Jan 31 2017 06:47
@Masd925 Yes you are right, the result of the division is not exact integer as I expected it to be. Thanks Markus for your time and help. :smile:
CamperBot
@camperbot
Jan 31 2017 06:47
:warning: pallavi-goyal already gave masd925 points
pallavi-goyal sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
ZenZate
@ZenZate
Jan 31 2017 06:48
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){
// Only change code below this line
 if (lookUpProfile.hasOwnProperty(firstName)){
   if(lookUpProfile.firstName.hasOwnProperty(prop)){
     var property = "";
     property = lookUpProfile.firstName.prop;
     return property;
   }else{
     return "No such property";
   }
 }else{
   return "No such contact";
 }
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
it isn't working
Noe Santiago
@Santiago7011
Jan 31 2017 06:50
help with 52 javascript. local vs global
CamperBot
@camperbot
Jan 31 2017 06:50
no wiki entry for: with 52 javascript local vs global
ZenZate
@ZenZate
Jan 31 2017 06:50
The end is the only bit I wrote
Markus Kiili
@Masd925
Jan 31 2017 06:51
@ZenZate Access contatcs array, not lookUpProfile, which is the function.
ZenZate
@ZenZate
Jan 31 2017 06:51
Oh wow
Markus Kiili
@Masd925
Jan 31 2017 06:51
First you need to loop or iterate through the array.
ZenZate
@ZenZate
Jan 31 2017 06:51
thaks @Masd925
Scott Spence
@spences10
Jan 31 2017 06:52
Is anyone able to help with node.js?
ZenZate
@ZenZate
Jan 31 2017 06:52
thx @Masd925
CamperBot
@camperbot
Jan 31 2017 06:52
zenzate sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 3265 | @masd925 |http://www.freecodecamp.com/masd925
Scott Spence
@spences10
Jan 31 2017 06:52
I want to get a result back from a module
module.exports = function (param) {
  var queryString = {}

  var db = require('./queryDB')

  // Check key isn't in db already, key being the param
  db.get(param, function (err, value) {
    if (typeof (value) !== 'undefined') {
      // console.log('ALREADY IN DB', param)
    } else {
      // Put a search query  
      db.put(param, Date(), function (err) {
        if (err) return console.log('Ooops!', err) // some kind of I/O error
        // console.log('LOGGED QUERY STRING', param)
      })
    }
  })

  return queryString + ' YO!'
}
I'm calling with :
  params = 'query'
  var s = require('./helpers/query')(params)
AudioGen
@AudioGen
Jan 31 2017 06:54
@Manish-Giri Yah I'm not understanding it now
Scott Spence
@spences10
Jan 31 2017 06:54
But have also tried:
getData(fetchData)

function fetchData (callback) {
  params = 'query'
  var s = require('./helpers/query')(params)
  callback(params)
}

function getData () {
  fetchData(function (params) { 
    console.log(params)
   })
}
as a callback
the callback works
but I dont get the return queryString + ' YO!'
ZenZate
@ZenZate
Jan 31 2017 06:55
It still isn't working
Vijith Nair
@wizelmagnifico
Jan 31 2017 06:58

function truncateString(str, num) {

var truncd = '';
if (num > 3){
if (str.length > num) {
truncd = str.slice(0,num-3) + '...';
return truncd;
}
}
return str;
}

truncateString("A-tisket a-tasket A green and yellow basket", 11);

can somebody help?
Scott Spence
@spences10
Jan 31 2017 06:58
@ZenZate no, I'm expecting the modified queryString appended qith ' YO!'
Manish Giri
@Manish-Giri
Jan 31 2017 07:05
@AudioGen I don't know what you don't understand
now getFirstName() and getLastName() are working fine.
AudioGen
@AudioGen
Jan 31 2017 07:07
@Manish-Giri Yah, I guess I don't understand why it needs to be made into an array?
We already had the first and last name separate with slice
Manish Giri
@Manish-Giri
Jan 31 2017 07:07
@AudioGen that's just my way, you can do whatever way you want
ultimately, you need to extract the firstname and lastname from the new fullName
and assign them to the firstand last variables, respectively.
AudioGen
@AudioGen
Jan 31 2017 07:08
Ok
@Manish-Giri Thanks for your help and time
CamperBot
@camperbot
Jan 31 2017 07:08
audiogen sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 4017 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Jan 31 2017 07:08
np

as for this question

We already had the first and last name separate with slice

first and last name was Bob and Ross, respectively
how would you change them to Haskell Curry without calling the constructor again?
ZenZate
@ZenZate
Jan 31 2017 07:11
I am not able to do Profile Lookup
I tried so many times
Feltope
@Feltope
Jan 31 2017 07:13
well I think I am messing up with the dot notation/bracket system that js has any clues?
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
}
Jor
@joreyesl
Jan 31 2017 07:14
@Feltope you have to use bracket notation because prop is a variable. contacts[i][prop].
Also you dont want to return No such contact inside the loop. remove that else statment and move the return outside of the loop.
OuRyoShin
@DJQTDJ
Jan 31 2017 07:14
how to solve this?
Refused to load the image 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA8Q1JFQVRPUjogZ2QtanBl…N+7+4n2O3www58sZc5bP0f8A/jpJ4LvLTwf4suvN8H3U/+gX83/Mt3Fxd/h/xJfb+XcooA/9k=' because it violates the following Content Security Policy directive: "default-src 'self' 'unsafe-eval' 'unsafe-inline'". Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.


Refused to load the image 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA8Q1JFQVRPUjogZ2QtanBl…N+7+4n2O3www58sZc5bP0f8A/jpJ4LvLTwf4suvN8H3U/+gX83/Mt3Fxd/h/xJfb+XcooA/9k=' because it violates the following Content Security Policy directive: "img-src * ".
Feltope
@Feltope
Jan 31 2017 07:15
okay thank you. thought I had tried that
Ogundele Olumide
@Lumexralph
Jan 31 2017 07:15
@Feltope when you're done looking through contacts with your loop return no such contact
@ZenZate What's the challenge? can you show your code?
ZenZate
@ZenZate
Jan 31 2017 07:18
@Lumexralph for(var i = 0; i < contacts.length; i++) { if(contacts[i].hasOwnProperty(firstName)) if(contacts[i].hasOwnProperty(prop)) return contacts[i].prop; else return "No such Property"; else return "No such contact"; }
Feltope
@Feltope
Jan 31 2017 07:18
hehe skipped over that had it inside the for. thanks. got it worked out now
ZenZate
@ZenZate
Jan 31 2017 07:19
I kept restarting
Ogundele Olumide
@Lumexralph
Jan 31 2017 07:19
@ZenZate you should first check if the firstName property of the object is equal to the firstName parameter
@Feltope you reference the names of people that helped you
Sam Houlahan
@Sam-Houlahan
Jan 31 2017 07:20

We have an array of objects representing different people in our contacts lists.

A lookUpProfile function that takes firstName and a property (prop) as arguments has been pre-written for you.

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"

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


function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i; i < contacts.length; i++){
  if( firstName===firstName){

  }
}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
OuRyoShin
@DJQTDJ
Jan 31 2017 07:20
how to solve this?
Refused to load the image 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA8Q1JFQVRPUjogZ2QtanBl…N+7+4n2O3www58sZc5bP0f8A/jpJ4LvLTwf4suvN8H3U/+gX83/Mt3Fxd/h/xJfb+XcooA/9k=' because it violates the following Content Security Policy directive: "default-src 'self' 'unsafe-eval' 'unsafe-inline'". Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.


Refused to load the image 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA8Q1JFQVRPUjogZ2QtanBl…N+7+4n2O3www58sZc5bP0f8A/jpJ4LvLTwf4suvN8H3U/+gX83/Mt3Fxd/h/xJfb+XcooA/9k=' because it violates the following Content Security Policy directive: "img-src * ".
Sam Houlahan
@Sam-Houlahan
Jan 31 2017 07:20
am i on the right track here guys.
Ogundele Olumide
@Lumexralph
Jan 31 2017 07:20
@keewhy initialise i to 0
Sam Houlahan
@Sam-Houlahan
Jan 31 2017 07:21
Sweet ty
Ogundele Olumide
@Lumexralph
Jan 31 2017 07:21
@keewhy you're on track using loop to pick each objects but remember each object will be contacts[i]
ZenZate
@ZenZate
Jan 31 2017 07:21
thanks @Lumexralph
CamperBot
@camperbot
Jan 31 2017 07:21
zenzate sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 905 | @lumexralph |http://www.freecodecamp.com/lumexralph
Jor
@joreyesl
Jan 31 2017 07:21
@keewhy you should be using your loop to iterate through the list and compare the ith contact's firstName with the firstName parameter, like if(contacts[i].firstName === firstName)
AudioGen
@AudioGen
Jan 31 2017 07:22
@Manish-Giri I guess it's not using a function declaration so it wouldn't hoist it to the top of the program, I think that's kind of where my line of thinking was at though
I thought if the firstAndLast was set to a different string, the first and last variables wouldn't hold the initial string because it's assigned to the slicing firstAndLast
ZenZate
@ZenZate
Jan 31 2017 07:24
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"; } } } return "No such contact";
Ogundele Olumide
@Lumexralph
Jan 31 2017 07:24
@ZenZate then you have another nested to check if prop parameter is a property of the object, if that's true return the value of that prop in the , if not return no such property
ZenZate
@ZenZate
Jan 31 2017 07:25
Oh I was missing a bracket
Ogundele Olumide
@Lumexralph
Jan 31 2017 07:25
@ZenZate i think you're right
ZenZate
@ZenZate
Jan 31 2017 07:25
I passed
Ogundele Olumide
@Lumexralph
Jan 31 2017 07:25
@ZenZate another suggestion.... listening?
ZenZate
@ZenZate
Jan 31 2017 07:26
Yh go on
I just got past the challenge
Ogundele Olumide
@Lumexralph
Jan 31 2017 07:26
@ZenZate you can remove the else statements.... return gives the value and exists the function
ZenZate
@ZenZate
Jan 31 2017 07:26
@Lumexralph thx
CamperBot
@camperbot
Jan 31 2017 07:26
zenzate sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:warning: zenzate already gave lumexralph points
Ogundele Olumide
@Lumexralph
Jan 31 2017 07:27
@ZenZate :+1:
Sam Houlahan
@Sam-Houlahan
Jan 31 2017 07:42

```function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i=0; i < contacts.length; i++)
if(contacts[i].firstName === firstName){

if(contacts[i].hasOwnProperty(prop)){
  return contacts[i].prop;

} else {
return "No such contact";
}

}

}

// Only change code above this line

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

```function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i=0; i < contacts.length; i++)
if(contacts[i].firstName === firstName){

if(contacts[i].hasOwnProperty(prop)){
  return contacts[i].prop;

} else {
return "No such contact";
}

}

}

// Only change code above this line

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

shit wont format it. Any ideas of where i am going wrong guys

function lookUpProfile(firstName, prop){
// Only change code below this line
```for (var i=0; i < contacts.length; i++)
if(contacts[i].firstName === firstName){

if(contacts[i].hasOwnProperty(prop)){
  return contacts[i].prop;

} else {
return "No such contact";
}

}

}
```
// Only change code above this line

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

GauravChandrawale
@GauravChandrawale
Jan 31 2017 07:46
Counting Cards .. plz help me for this lesson
return count + (count > 0 ? " Bet" : " Hold");
Satyam Saurabh
@satyam2401
Jan 31 2017 07:46
@keewhy You also have to return no such property in case the property does not matches. check instructions.
GauravChandrawale
@GauravChandrawale
Jan 31 2017 07:46
hw this line works
coko100
@coko100
Jan 31 2017 07:46

Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr

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

}

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

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

Jor
@joreyesl
Jan 31 2017 07:47
@keewhy your logic should look like
1.Loop - Iterate through the list
  a. If firstName matches, then check prop
   a.1 If contact has prop, then return prop
   a.2 Else return  no such property
2.End loop.
3. If loop ends, then that means the contact was not found, so return no such contact.
Ogundele Olumide
@Lumexralph
Jan 31 2017 07:47
@keewhy prop is a parameter use bracket method
@coko100 use your 2 loops iterator to access array arr and multiply with product
Jor
@joreyesl
Jan 31 2017 07:48
@GauravChandrawale That return looks fine, are you also making sure you are updating the count prior to the return?
GauravChandrawale
@GauravChandrawale
Jan 31 2017 07:49
@joreyesl code is working bt m unable to understand last line working "return count + (count > 0 ? " Bet" : " Hold");"
Sam Houlahan
@Sam-Houlahan
Jan 31 2017 07:50
@Lumexralph so it should be something like return contacts[i].(prop);?
GauravChandrawale
@GauravChandrawale
Jan 31 2017 07:50
count > 0? why thr r "?" this sign
Ogundele Olumide
@Lumexralph
Jan 31 2017 07:50
@coko100 not var product += arr[i][j].... it's outside the loop, you get undefined put it in the loop and change it to multiplication
@keewhy [ ]
Jor
@joreyesl
Jan 31 2017 07:51
@GauravChandrawale That the ternary operator. Basically like an if else state. Check if count > 0, if true, the returns " Bet", if false return " Hold".
@keewhy should be contacts[i][prop], using brackets because prop is a variable.
GauravChandrawale
@GauravChandrawale
Jan 31 2017 07:53
@joreyesl this explaination help me ... thnk u a lott
Sam Houlahan
@Sam-Houlahan
Jan 31 2017 07:53
Okay thanks
Satyam Saurabh
@satyam2401
Jan 31 2017 07:53
Screenshot (22).png
Why is that one case not running?
Ogundele Olumide
@Lumexralph
Jan 31 2017 07:54
@satyam2401 can you post the code?
Satyam Saurabh
@satyam2401
Jan 31 2017 07:54
Ok, wait a sec.

function diffArray(arr1, arr2) {
  var newArr = [];
  var newarr=[];

  newarr=arr1.concat(arr2);

  newarr=newarr.sort();

  newarr.sort(function(a,b){
    return b-a;
  });

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

  if(newarr[i]==newarr[i+1]){
    newarr.splice(i,2);
    i=0;
  }

  }

  newArr= newarr;


  // Same, same; but different.
  return newArr;
}
Here it is.
Michael Davis
@mdavis93
Jan 31 2017 08:04
Just started the ROT13 challenge and I'm finding myself drawing a blank. I'm going over my notes from all the previous lessons and I can't figure out which lesson this challenge pulls from. Which lesson should I re-visit for this challenge, or (if not directly related to any one lesson), what external resource should I consult?
coko100
@coko100
Jan 31 2017 08:11
@Lumexralph thanks man :smile:
CamperBot
@camperbot
Jan 31 2017 08:11
coko100 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 906 | @lumexralph |http://www.freecodecamp.com/lumexralph
Sam Houlahan
@Sam-Houlahan
Jan 31 2017 08:18
// Example
function ourRandomRange(ourMin, ourMax) {

  return Math.floor(Math.random() * (ourMax - ourMin + 1)) + ourMin;
}

ourRandomRange(1, 9);

// Only change code below this line.

function randomRange(myMin, myMax) {

  return Math.floor(Math.random()>=myMin && <=myMax) ; // Change this line

}

// Change these values to test your function
var myRandom = randomRange(5, 15);
any help with this guys
Michael Davis
@mdavis93
Jan 31 2017 08:20
Math.floor() returns the "nearest whole number, less than the provided number", but you are passing a logical check to it
Sam Houlahan
@Sam-Houlahan
Jan 31 2017 08:21
Create a function called randomRange that takes a range myMin and myMax and returns a random number that's greater than or equal to myMin, and is less than or equal to myMax, inclusive.
Michael Davis
@mdavis93
Jan 31 2017 08:22
Math.floor() is expecting to operate on a number, but >= and && are both boolean operators that return a true or false answer.
Remember, Math.random() creates a random number between 0 and 1, never quite reaching 1. Remember how to make that fit any range you need?
Jor
@joreyesl
Jan 31 2017 08:23
@satyam2401 found the cause, inside your if statement you have i=0, which then gets incremented by i++ at the end of the iteration, which means you will end up checking newarr[1] == newarr[2] instead of newarr[0] == newarr[1]. Quick way to fix, is move i++ to inside the loop at the end of the iteration. and inside your if statement add a continue right after i=0.
Sam Houlahan
@Sam-Houlahan
Jan 31 2017 08:26
hmmm :(
Muhammad Hasham
@MohammadHasham
Jan 31 2017 08:28
has anyone done "electronic game" project mentioned in eloquent javascript. ?
Michael Davis
@mdavis93
Jan 31 2017 08:28
Look at the Example they give in the exercise, Math.floor(Math.random() * (ourMax - ourMin + 1)) + ourMin;
Above was to @keewhy
Reggie
@Reggie01
Jan 31 2017 08:28
@mdavis93 what category is ROT13 under on the map
Michael Davis
@mdavis93