These are chat archives for FreeCodeCamp/HelpJavaScript

24th
Apr 2017
cjlynch12
@cjlynch12
Apr 24 2017 00:01
@khaduch tried both, no luck with either
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 00:03

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

  // Only change code below this line
  var lookup = {
    "alpha": "Adams",
    "bravo": "Boston",
    "charlie": "Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "Frank"
  }

  switch(val) {
    case "alpha": 
      result = "Adams";
      break;
    case "bravo": 
      result = "Boston";
      break;
    case "charlie": 
      result = "Chicago";
      break;
    case "delta": 
      result = "Denver";
      break;
    case "echo": 
      result = "Easy";
      break;
    case "foxtrot": 
      result = "Frank";
  }

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

// Change this value to test
phoneticLookup("charlie");
how do i convert this switch statement into an object?
Ken Haduch
@khaduch
Apr 24 2017 00:04
@cjlynch12 - well, I tried using http://codepen.io/cjlynch12/pen/XRKQMe, and I see some data being returned, perhaps only the data.id value is being set? But that definitely got output to the zipcode value field on your HTML page.
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 00:04
I am trying to get rid of the switch statement all together
Ken Haduch
@khaduch
Apr 24 2017 00:05
@Rafewey - you converted it to an object, so you should delete the switch statement. Then just access the object using the val variable to assign a value to result.
This message was deleted
This message was deleted
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 00:07
@khaduch I know I should delete the switch statement, but I am using it as a reference.
cjlynch12
@cjlynch12
Apr 24 2017 00:07
@khaduch omg I'm an idiot, I thought you mean the http prefix on the embedded link the JS, not the codepen link
@khaduch that did it, thanks
CamperBot
@camperbot
Apr 24 2017 00:07
cjlynch12 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2778 | @khaduch |http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Apr 24 2017 00:09
@Rafewey - okay, so you don't need to have it in there once you make the proper translations between the various cases in the switch and the object. Each property in the object corresponds to one of the switch statement's cases, so that looks good. Now you just have to formulate the proper object access to get the desired values into result.
Pagnito
@Pagnito
Apr 24 2017 00:10
how come in where art thou says that for the third requirement it should return two objects, when the other objects alsHey, can anyone help me with "Where are thou" I made an algorithm that i thought would work and it does for the first two cases, but for some reason in the third it should only return 2 objects, but the other objects also have the source argument so my algorithm returns them too, i dont understand the problem anymore
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 00:10
@khaduch Thats what I am trying to do. I just have been sitting here for 20-30m just trying to figure out how.
Pagnito
@Pagnito
Apr 24 2017 00:10
Hey, can anyone help me with "Where are thou" I made an algorithm that i thought would work and it does for the first two cases, but for some reason in the third it should only return 2 objects, but the other objects also have the source argument so my algorithm returns them too, i dont understand the problem anymore
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:11
Hey there campers, I can't figure out why the data the JSON data wont load
Pagnito
@Pagnito
Apr 24 2017 00:12
ooh i think i get it, it shouldnt return ones that only have one of the keys
Ken Haduch
@khaduch
Apr 24 2017 00:12
@Rafewey - check out the example code - they show a simple variation of doing this with the alpha object. Note that this is similar to the "Accessing Objects Properties with Variables" lesson, or based on the concept in that lesson.
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:12
In JS editor I have a test link that you can use for replacement to test
I can't figure out why open weather map won't output data for me
Ken Haduch
@khaduch
Apr 24 2017 00:15
@Giveback007 - switch to using http:// to access your CodePen project, and add http:// on the front of the weather page URL in your JS code. You have to have http:// to access openweather, so you have to also use http://codepen.io/giveback007/pen/wdWVZz?editors=1011 to access the top-level project.
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:16
could you elaborate what is a top level project?
Keon Samuel
@keonsam
Apr 24 2017 00:18
is there a better way of doing this?

let a = 8, b = 6;
// change code below this line
var num=[8,6];
[b,a]= num;
// change code above this line
console.log(a); // should be 6
console.log(b); // should be 8
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:18
i've just inserted the http:// and it still wont log
@keonsam is that the whole code?
Keon Samuel
@keonsam
Apr 24 2017 00:19
yes
Gulsvi
@gulsvi
Apr 24 2017 00:19
@Giveback007 Ken was saying to use this URL for your codepen project: http://codepen.io/giveback007/pen/wdWVZz?editors=1011
Make sure it starts with http://
Ken Haduch
@khaduch
Apr 24 2017 00:20
@Giveback007 - the URL that you use to access your COdePen project page, which I put in my previous note, is what I refer to as the "top-level" project. How you access your page, in other words. Any accesses that happen within the page have to match the same access type - so you have to use http:// for the free openweather access, and your top page has to also be accessed with http://
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:20
@keonsam I don't remember seeing 'let' beffor, what does it do?
Keon Samuel
@keonsam
Apr 24 2017 00:20
create a variable lol.
it is in freecodecamp beta.
Ken Haduch
@khaduch
Apr 24 2017 00:20
@Giveback007 - let is an ES6 keyword to declare a variable, with some additional properties to it, like how it is scoped, etc.
Keon Samuel
@keonsam
Apr 24 2017 00:21
have you ever seen this?
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:21
no
I am doing the regular track not beta
Keon Samuel
@keonsam
Apr 24 2017 00:21
const{x,y,z} =a;
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:21
no that is interesting.
are you giving 3 variables the same value?
Keon Samuel
@keonsam
Apr 24 2017 00:22
nope
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:22
@khaduch my data still wont load
Saboor Malik
@MathematicsCoding
Apr 24 2017 00:22
Im back..
ViewSearch Virus?
Gulsvi
@gulsvi
Apr 24 2017 00:23
image.png
@Giveback007 Your data loads fine. Make sure the address in your address bar starts with HTTP://
Ken Haduch
@khaduch
Apr 24 2017 00:24
@Giveback007 - I just loaded your project from the link that @SkyCoder01 posted, and it works. Do you have a different link now?
Saboor Malik
@MathematicsCoding
Apr 24 2017 00:24
@SkyCoder01 you on?
Gulsvi
@gulsvi
Apr 24 2017 00:24
Nope @MathematicsCoding
Not here :)
Saboor Malik
@MathematicsCoding
Apr 24 2017 00:24
oh wrong chat...
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:25
wha.....
Ken Haduch
@khaduch
Apr 24 2017 00:25
@Giveback007 - data is being logged to the console...
Keon Samuel
@keonsam
Apr 24 2017 00:25
@Giveback007 how about this: ```const [a,b,...arr] = source;
const [a,b,...arr] = source;
Saboor Malik
@MathematicsCoding
Apr 24 2017 00:26
@SkyCoder01 can you come to frontend chat?
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:26
theres some king of effery going on and I can't figure out what
Ken Haduch
@khaduch
Apr 24 2017 00:27
@Giveback007 - make sure that you have http:// in both places? Sometimes reloading the page will switch back to https:// - check your browser console for errors (not the console in the CodePen, but the actual browser console from devtools.)
Keon Samuel
@keonsam
Apr 24 2017 00:28

const profileUpdate = (profileData) => {
  const { name, age, nationality, location } = profileData;
how about that?
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:28
Capture.PNG
Joshua Wynns
@jwynns
Apr 24 2017 00:29

Hey everyone, I'm having issues with jquery/contact form and not sure what's wrong. The console does return any error messages.

I'm trying to get the form to do a transition when you click in it, and it works in codepen but not when I add the code to my site.

http://codepen.io/jwynns-14724379/pen/MmjgLL

My site
https://github.com/jwynns/cause

If anyone can go over the code, I'll appreciate the help. Idk if the issue is with the css or with the jquery.

Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:30
it finally loaded
time for brownie points @khaduch @SkyCoder01 thank you
CamperBot
@camperbot
Apr 24 2017 00:30
giveback007 sends brownie points to @khaduch and @skycoder01 :sparkles: :thumbsup: :sparkles:
:star2: 1155 | @skycoder01 |http://www.freecodecamp.com/skycoder01
:star2: 2779 | @khaduch |http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Apr 24 2017 00:31
@Giveback007 - see, your top-level page is being loaded with https:// again. So you are getting the "MIxed content" error again...
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:31
so can you explain to me a little more why that was a problem?
Gulsvi
@gulsvi
Apr 24 2017 00:32
@Giveback007 You were hitting a Mixed Content issue. It happens when you open a web page over HTTPS and try to access resources over HTTP. https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:34
lol just now I realized that you guys were emphesizing htt's' I didn't see the difference at first
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 00:35
Can someone tell me why this is wrong?
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  if (myObj.hasOwnProperty(checkProp) === true){
    return myObj.checkProp;
  }
  else {
    return "Not Found";
  }
  return "Change Me!";
}

// Test your code by modifying these values
checkObj("gift");
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:36
is there a way to circumvent this issue? what if someone visiting my site load it in one or the other?
Gulsvi
@gulsvi
Apr 24 2017 00:36
@Giveback007 You'll need to use a weather API that supports HTTPS. Open Weather Map, unfortunately, only works over HTTP.
Ken Haduch
@khaduch
Apr 24 2017 00:36
@Rafewey - you have to use bracket notation to access your object when you have the property name in a variable.
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 00:37
@khaduch Does it have to be quotes?
i quotes*
in*
Gulsvi
@gulsvi
Apr 24 2017 00:37
@Giveback007 For all of the web apps you develop, use HTTPS for everything, that's generally the best way to avoid Mixed Content Errors.
luke1998
@luke1998
Apr 24 2017 00:39
how do I assigned contents of "a" to variable "b"?
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:39
@SkyCoder01 isn't open weather map being used by professional app developers? how do they circumvent it? ... they even have a paid sub model
also can someone load my page in http when I am using an https api?
Keon Samuel
@keonsam
Apr 24 2017 00:41
I don't know what the hell I am doing.

const stats = {
  max: 56.78,
  standard_deviation: 4.34,
  median: 34.54,
  mode: 23.87,
  min: -0.75,
  average: 35.85
};
// change code below this line
const half = ({max:a, min:b}) => ((a+ b) / 2.0); // use function argument destructurung
// change code above this line
console.log(stats); // should be object
console.log(half(stats)); // should be 28.015
Ken Haduch
@khaduch
Apr 24 2017 00:41
@Rafewey - no, the variable name should be in brackets, and it should not be in quotes, otherwise it will be treated as a string.
Keon Samuel
@keonsam
Apr 24 2017 00:42
oh I see.
console.log(half(stats));
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:43
@luke1998 lets pretend that [var a = 8;] and I do [var b = a;] then [b = 8;]
Keon Samuel
@keonsam
Apr 24 2017 00:43
that part makes the computer know where to reference.
lol what? no
luke1998
@luke1998
Apr 24 2017 00:43
thanks @Giveback007
CamperBot
@camperbot
Apr 24 2017 00:43
luke1998 sends brownie points to @giveback007 :sparkles: :thumbsup: :sparkles:
:cookie: 267 | @giveback007 |http://www.freecodecamp.com/giveback007
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:45
basicly you gave b the value of a by assigning variable a to b
Todd Abraham
@toddabraham
Apr 24 2017 00:45
Working on the first Basic Algorithm Scripting exercise - Reverse a String. I discovered this article https://medium.freecodecamp.com/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb - which is helpful, but offers three different alternatives to solve the problem. This leads me to the question of “how the heck does one choose the best method to solve a problem when there are so many routes to the solution?”.

feelingoverwhelmed

Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:46
@toddabraham depends on what you are trying to achieve, generally less lines of code and speed (i believe) is what most coder are trying to achieve
Keon Samuel
@keonsam
Apr 24 2017 00:46
@toddabraham no best method in programming what work works.
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:47
@toddabraham because we are not creating industry software that relies on performance it's best to take the route that is the easiest for you to take.
Rhys
@105ron
Apr 24 2017 00:47
Is the testing on FCC a little broken at the moment
Keon Samuel
@keonsam
Apr 24 2017 00:48
Of course there is a faster and shorter route.
Rhys
@105ron
Apr 24 2017 00:48
My function returns the right result but the test says it fails
Ken Haduch
@khaduch
Apr 24 2017 00:50
@105ron - double check your result - you might have hidden spaces, one thing that I've seen a number of times is a trailing space on a string, for example, that causes the tests to fail, even though the result appear to be correct. Want to share your code for another opinion?
Henry
@GitHub-Henry
Apr 24 2017 00:50
@jwynns you sent repository link, where is the link that shows the site up and running?
Todd Abraham
@toddabraham
Apr 24 2017 00:51
I tend to lean toward @Giveback007 ’s response. But following the idea of less lines leads to better code efficiency, if you read the solution #3 in the article where the author uses Recursion to solve, you see this option offers the most code lines, but is shortened with the Ternary Operator. The author goes on to mention that this is still a bloated method for solving. Does that mean to say that even though the Ternary Operator shortens the code, this method is still more taxing on the system?
Rhys
@105ron
Apr 24 2017 00:51
@khaduch
function smallestCommons(arr) {
  function isDivisibleBy(element, index, array) {
    return j % element === 0;
  }
  var range = [];
  if (arr[0] > arr[1]) {
    arr[1] = [arr[0],arr[0]=arr[1]][0]; //swap elements
  }

  for (var i = arr[0]; i <= arr[1]; i++) {
    range.push(i);
  }
  for (var j = 3; j < 9000000; j++) {
    if (range.every(isDivisibleBy)) {
      return j;
    }
  }
}
console.log(smallestCommons([23, 18]));
Hanif Carroll
@HanifCarroll
Apr 24 2017 00:52
Hello! Can anyone help me with the "largest of four" problem? I can't figure out why my code isn't working. When I run through it in my head, it seems like it should work.
https://pastebin.com/raw/zV0crHL6
Rhys
@105ron
Apr 24 2017 00:52
It returns 6056820 which is the expected result for 23,18
Todd Abraham
@toddabraham
Apr 24 2017 00:53
@Giveback007 should have read your last statement before submitting my last question. So in JavaScript, efficiency doesn’t have to be as much of a concern?
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:54

@toddabraham I barley know how to write code, I haven't even gotten in to testing the performance of the code I write. I think it doesn't mater until you are trying to scale when your code is running a million times trough a server.

I believe there are tools to test the performance of your code if that is what you are looking for

Ken Haduch
@khaduch
Apr 24 2017 00:55
@105ron - it is flagging that as a potential infinite loop, outputting the message that I cannot copy that says a potential infinite loop exists.
Rhys
@105ron
Apr 24 2017 00:56
How does FCC flag a potential inifinite loop though? Can I change my code to get around it?
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:56
@toddabraham (I think, without a foundation of knowledge) professional developers will tend to build their apps as fast as possible, then at a later time refactor them to be more efficient
Fatbacker
@fatbacker
Apr 24 2017 00:56

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

// Your code above this line
return result ;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");

I am supposed to type something between the // lines and I have no clue what to type. This is so stupid.
Daniel Molina
@Molina92
Apr 24 2017 00:57
Hi! goodnight, hope that all of u're ok ... i have a little question, and when i put a switch statement of a variable in the break line the editor of freecodecamp says 'unreachable' break after return (the code works, its a yellow advisement)... Here is my code:
switch (val) {
    case 1 :
      return "alpha";
      break;
    case 2 :
      return "beta";
      break;
    case 3 :
      return "gamma";
      break;
    case 4 :
      return "delta";
      break;
  }
Todd Abraham
@toddabraham
Apr 24 2017 00:58
@Giveback007 Following the minimum viable product I guess. Bang something out and get to market as fast as possible, then improve following user feedback.
Ken Haduch
@khaduch
Apr 24 2017 00:59
@105ron - if you add the string // noprotect at the very top of your code, it will work. But you are incrementing your loop variable by one, which is causing a long run time for the larger numbers.
Dovydas Stirpeika
@Giveback007
Apr 24 2017 00:59
@toddabraham pretty much, but don't quote me on it. I have no authoraty on this.
Rhys
@105ron
Apr 24 2017 01:01
Thanks @khaduch . I couldn't think of a better way to do it for the time being
CamperBot
@camperbot
Apr 24 2017 01:01
105ron sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2780 | @khaduch |http://www.freecodecamp.com/khaduch
Rhys
@105ron
Apr 24 2017 01:02
There's a lot of numbers to check in the lower functions...
Justin Chan
@chinesescorpions
Apr 24 2017 01:04
@Molina92 , my friend, you type wrong code, you should use
answer = ""
@Molina92 , my source code is as below
function myTest(val) {
  var answer = "";
  // Only change code below this line
  switch (val) {
    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
myTest(1);
@Molina92 , before asking questions, pls advise challenge name to us, or i need to go back to search it.
I need help with this question please.
Ken Haduch
@khaduch
Apr 24 2017 01:08
@105ron - my suggestion is to increment your variable by the larger of the two numbers, since the only way a multiple of the larger value will be found is to keep adding the same value to the number you are testing.
Fatbacker
@fatbacker
Apr 24 2017 01:08
I have no clue how to answer it.
Pagnito
@Pagnito
Apr 24 2017 01:09
having trouble with "Where art thou" anyone up to help?. I just need to figure out how to make sure that the collection has BOTH of the keys from source
Ken Haduch
@khaduch
Apr 24 2017 01:09
@fatbacker -you should be using the function arguments within the function body, and concatenating them together to form a string with spaces between each word. In other words, result = myNoun + " " + myAdjective etc.
Manish Giri
@Manish-Giri
Apr 24 2017 01:10
@fatbacker your spamming the github repo won't do anything.
Ken Haduch
@khaduch
Apr 24 2017 01:10
@Pagnito = what does your current code look like?
Dalton Escoe
@Alenero129
Apr 24 2017 01:10
if (navigator.geolocation) If I see a if statement like that, should I interpret it as if navigator.geolocation returns a value that is not null, NaN or '', do this?
Fatbacker
@fatbacker
Apr 24 2017 01:10
I don't know how to use the function arguments.
Manish Giri
@Manish-Giri
Apr 24 2017 01:10
thousands of people have done the same challenges as you are doing, lots of them were absolute newbies

how did they manage to do it? If you think -

You people write this code like we are supposed to actually know it.

Fatbacker
@fatbacker
Apr 24 2017 01:11

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

// Your code above this line
return result ;
}

// Change the words here to test your function
wordBlanks("cat", "little", "hit", "slowly");

David Rowan III
@rowanD72
Apr 24 2017 01:11
Hello everyone
Dalton Escoe
@Alenero129
Apr 24 2017 01:11
hey, David
Fatbacker
@fatbacker
Apr 24 2017 01:11
I have no clue what to put between those spaces.
Ken Haduch
@khaduch
Apr 24 2017 01:11
@fatbacker - look at the example that I posted in my previous comment - it has an actual piece of usable code to help you solve the problem. :point_up: April 23, 2017 9:09 PM
Rhys
@105ron
Apr 24 2017 01:11
@khaduch that is a lot quicker now. Makes a big difference...
David Rowan III
@rowanD72
Apr 24 2017 01:12
Hello @Alenero129
Ken Haduch
@khaduch
Apr 24 2017 01:12
@105ron - it's a logical approach to the problem - glad it worked!
Justin Chan
@chinesescorpions
Apr 24 2017 01:12
@fatbacker, for argument in function, you need to goolge it. very simple. for word blank challenge, you are asked to make a sentence.
Kristen
@kgoooo
Apr 24 2017 01:12
Hey all, I am working on the palindrome exercise, and I am trying to get a regEx to filter out special characters but NOT numbers and am having a very hard time XD and cant get it to work for "1 eye for of 1 eye." , but it did work for "2_A3*3#A2".. so I'm very confused. using this
return str.replace(/([^abc\^0-9])/g, "");
David Rowan III
@rowanD72
Apr 24 2017 01:14
I finally made it to the javascript room! I was in a water cooler room a minute ago. No one was talking code.
Joseph
@revisualize
Apr 24 2017 01:14
Hello.
@kgoooo You should look at doing a range of alpha characters.
Ken Haduch
@khaduch
Apr 24 2017 01:14
@fatbacker - take time to study this infographic about functions. https://cs.wellesley.edu/~cs110/lectures/L16/images/function-anatomy.png
David Rowan III
@rowanD72
Apr 24 2017 01:15
I need a little help with some code I'm trying to get to work. Anyone willing to chat one one one to help me figure out what I am doing wrong?
Fatbacker
@fatbacker
Apr 24 2017 01:15
@khaduch Thanks, I will check it out. T
CamperBot
@camperbot
Apr 24 2017 01:15
:star2: 2781 | @khaduch |http://www.freecodecamp.com/khaduch
fatbacker sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
Ken Haduch
@khaduch
Apr 24 2017 01:16
@fatbacker - I"m having trouble getting it to load right now - perhaps the site is down?
Joseph
@revisualize
Apr 24 2017 01:16

@fatbacker String concatenation with variables.
Gist by revisualize / FreeCodeCamp - Word_Blanks.js
The function declaration was set up as... function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) giving the function name as wordBlanks and with four parameter of myNoun, myAdjective, myVerb and myAdverb.
There is more that I could go into (if you want I can) but, I'll sum it up with:
Parameters are treated like variables that represent the values that get passed into your function from the function call (arguments).

Here's a brief example about how to use parameters:

function hello(fName, uName) {
     return "Hello " + fName + " " + uName + ", How is your day?";
}
hello("Joseph", "@revisualize"); // "Hello Joseph @revisualize, How is your day?"
hello("Bella", "@bellaknoti"); // "Hello Bella @bellaknoti, How is your day?"
hello("Andy", "@dirn"); // "Hello Andy @dirn, How is your day?"

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

My simple example uses two parameters whereas wordBlanks has 4 parameters.

Dalton Escoe
@Alenero129
Apr 24 2017 01:16
@fatbacker Return the arguments passed to the function as a string. Take a look at the tests to see how it should be formatted.
Joseph
@revisualize
Apr 24 2017 01:16
@khaduch I like that graphic for explaining parameters.
Greg Duncan
@GregatGit
Apr 24 2017 01:17
@rowanD72 sure
Fatbacker
@fatbacker
Apr 24 2017 01:17
@revisualize Thanks Joseph.
CamperBot
@camperbot
Apr 24 2017 01:17
fatbacker sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3819 | @revisualize |http://www.freecodecamp.com/revisualize
David Rowan III
@rowanD72
Apr 24 2017 01:17
@khaduch I will also look at this.
thanks for the share @khaduch
CamperBot
@camperbot
Apr 24 2017 01:17
rowand72 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2782 | @khaduch |http://www.freecodecamp.com/khaduch
Joseph
@revisualize
Apr 24 2017 01:17
I have a complete write-up about parameters.
If people want I can post it.
Fatbacker
@fatbacker
Apr 24 2017 01:18
I have never done any of this before so figuring it out is hard enough without good examples.
Joseph
@revisualize
Apr 24 2017 01:19
@fatbacker My example is a good example.
@fatbacker You just may not realize it is a good example until after you figure out the challenge.
Fatbacker
@fatbacker
Apr 24 2017 01:20
@revisualize I added it to my code so i can follow it.
The whole point is that this is a tutorial and is supposed to teach us. Not keep us guessing.
I am sure it is easy when you already know the answer.
Joseph
@revisualize
Apr 24 2017 01:21
@fatbacker How to use parameters.

If I have this code:

function addThree (num) {
    var result;
    result = num + 3;
    return result;
}

So, when we make the function call of:

addThree(10);

You're calling the function addThree You're also passing a value 10 as an argument.
In the function declaration of function addThree (num) { You see that there is a parameter defined of num
When we do addThree(10) then the value of the parameter num is passed the argument value of ... 10
Then if you follow the code through.. result = num + 3; ... and we know the value of num is 10.
Therefore, if we follow through the function we end up with ... result = 10 + 3; then result = 13; then we return the result.

David Rowan III
@rowanD72
Apr 24 2017 01:22
Who in this room that's not new to javascript?
Joseph
@revisualize
Apr 24 2017 01:22
@rowanD72 What classifies as being new to JavaScript?
Fatbacker
@fatbacker
Apr 24 2017 01:22
I have never typed javascript code until today.
That classifies me as new. :)
David Rowan III
@rowanD72
Apr 24 2017 01:23
@revisualize one that understands more than the newbies
Justin Chan
@chinesescorpions
Apr 24 2017 01:23
@Fatbacker know what y mean, you need to read tutorial in MDN and professional books like eloquent Javascript
Joseph
@revisualize
Apr 24 2017 01:23
@rowanD72 What if I still classify myself as a newbie even though I've been doing this for almost a year and a half.
Pagnito
@Pagnito
Apr 24 2017 01:24
@khaduch oops sry, i thought i would get notifed if someone replied
Joseph
@revisualize
Apr 24 2017 01:24
@rowanD72 Better yet, what is the point of your question?
David Rowan III
@rowanD72
Apr 24 2017 01:24
I would say that I feel your pain @revisualize
Fatbacker
@fatbacker
Apr 24 2017 01:24
I just think the people who make these who make the questions forget what it is like to be a complete noob at all of this.
Joseph
@revisualize
Apr 24 2017 01:25
@fatbacker The instructions for the challenge are quite clear. A lot of people have completed the challenge from the instructions.
@fatbacker Have you completed the challenge?
Manish Giri
@Manish-Giri
Apr 24 2017 01:25
thousands of people have done the same challenges as you are doing, lots of them were absolute newbies
how did they manage to do it? If you think -
You people write this code like we are supposed to actually know it.
Justin Chan
@chinesescorpions
Apr 24 2017 01:26
@revisualize you can try codecademy.com first
David Rowan III
@rowanD72
Apr 24 2017 01:26
One minute I get javascript and then there are times I feel like I don't know nothing .
Fatbacker
@fatbacker
Apr 24 2017 01:26
@revisualize No I have not finished it yet. I am still struggling with it.
Manish Giri
@Manish-Giri
Apr 24 2017 01:26
@fatbacker you should do codeacademy's js lessons first.
Joseph
@revisualize
Apr 24 2017 01:26
@fatbacker I didn't know JavaScript before working on the same challenge that you're working on now.
@chinesescorpions I've completed Codecademy.
Long Nguyen
@longnt80
Apr 24 2017 01:27

hello, I need help with the Challenge: Title Case a Sentence

function titleCase(str) {

   //Split str
   var wordSplit = str.toLowerCase().split(/\s/g);

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

      //Split each word
      var letterSplit = wordSplit[i].split('');

      //Change the firt Letter to Uppercase and Join everything back
      letterSplit[0] = letterSplit[0].toUpperCase();
      wordSplit[i] = letterSplit.join('');
      var newStr = wordSplit.join(' ');
      return newStr;
   }

}

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

the return statement only return the first result from the loop, how can I select the last output of the loop to get the full sentence?

Joseph
@revisualize
Apr 24 2017 01:27
@chinesescorpions I've completed most of the front end JavaScript for freeCodeCamp.
Justin Chan
@chinesescorpions
Apr 24 2017 01:27
really? there are dozens of course there
@revisualize it is good
Joseph
@revisualize
Apr 24 2017 01:27
@chinesescorpions I disagree.
Kristen
@kgoooo
Apr 24 2017 01:27
@revisualize I tried that as well.. I found a range on stack overflow like this:
return str.replace(/([.*+?^=!/-:${}_,()|\[\]\/\\][^0-9])/g, "");
but also ran into problems with it removing the 1's and then leaving the "." so I tried [^0-9] and also no luck... or do you mean something completely different?
oops that example obv has 0-9 in it, but yeah
Joseph
@revisualize
Apr 24 2017 01:28
@kgoooo YOu don't need that. You should focus on what you wrote before
@kgoooo You need to remove all non-alphanumeric characters. The opposite of that though process is... You need to keep all alphanumeric characters.
Kristen
@kgoooo
Apr 24 2017 01:29
shouldnt NOT abc and NOT numbers leave.. only *&^%$# etc..
hmm
Ken Haduch
@khaduch
Apr 24 2017 01:29
@Pagnito - using the approach that you are using is doable. You just have to recognize that there could be more than one key, and use an inner loop to process all of them, checking that each one of them has a match in the particular collection object. You could also use the .every() method.
Joseph
@revisualize
Apr 24 2017 01:29
@kgoooo What if all the alpha characters were a range instead of defining just the characters a, b and c.
Pagnito
@Pagnito
Apr 24 2017 01:29
@khaduch never heard of every() method
Joseph
@revisualize
Apr 24 2017 01:30
@kgoooo a range of all alpha characters are a-z
Pagnito
@Pagnito
Apr 24 2017 01:30
@khaduch yea thats what i figured, it seems hasOwnProperty only checks one property
Kristen
@kgoooo
Apr 24 2017 01:30
oh shit does abc not unclude ALL the letters? ah hahahaha
Pagnito
@Pagnito
Apr 24 2017 01:30
@khaduch will that work on a object tho?
Kristen
@kgoooo
Apr 24 2017 01:30
@revisualize oops , that would probably make a lot more sense XD
Joseph
@revisualize
Apr 24 2017 01:30
@kgoooo abc in regex is just three characters.
Ken Haduch
@khaduch
Apr 24 2017 01:31
@Pagnito - you have to figure out a way to use it. But it can be used.
Kristen
@kgoooo
Apr 24 2017 01:31
@revisualize ahh ok thank you so much!
CamperBot
@camperbot
Apr 24 2017 01:31
kgoooo sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3820 | @revisualize |http://www.freecodecamp.com/revisualize
Pagnito
@Pagnito
Apr 24 2017 01:31
@khaduch cool coolm is every() pretty much like filter()>
?
Joseph
@revisualize
Apr 24 2017 01:31
@kgoooo Starting to make sense?
@fatbacker How are you doing with your challenge?
Pagnito
@Pagnito
Apr 24 2017 01:32
@khaduch oh nvm, it doesnt return a new array as i see it
Kristen
@kgoooo
Apr 24 2017 01:33
@revisualize yes! I was referencing regEx expression examples and they all just say [abc] so I figured.. it was literally [abc] silly me . thank you so much!
CamperBot
@camperbot
Apr 24 2017 01:33
kgoooo sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: kgoooo already gave revisualize points
Ken Haduch
@khaduch
Apr 24 2017 01:33
@Pagnito - in fact, I used .filter() and .every() to solve this. Filter each item in collection using .every() to do the testing.
Joseph
@revisualize
Apr 24 2017 01:33
If anyone wants assistance with any of the beginner challenges (beginning JavaScript Algorithms (except seek and destroy) downward.) I'm willing to jump in a live / pair programming session.
Pagnito
@Pagnito
Apr 24 2017 01:34
@khaduch hmm, k, thanks
CamperBot
@camperbot
Apr 24 2017 01:34
pagnito sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2783 | @khaduch |http://www.freecodecamp.com/khaduch
Pagnito
@Pagnito
Apr 24 2017 01:35
@khaduch if using filter tho, y do u need to use every()?
Ken Haduch
@khaduch
Apr 24 2017 01:36
@Pagnito - but you can do it without that. My original solution was much more literal - only used for loops and logic to track the matching values.
You don't need to use .every() at all - it is just a neat solution. All you have to do within .filter is determine a true or false value to return. You can do it with .every() or with a slightly more complicated-looking for loop.
Pagnito
@Pagnito
Apr 24 2017 01:37
@khaduch hmm think im gettgin what u saying
Pagnito
@Pagnito
Apr 24 2017 01:44
@khaduch i cant use filter on a object tho
Ken Haduch
@khaduch
Apr 24 2017 01:46
@Pagnito - if you use collection.filter( function(item) { // code } - each item is going to be an element from the collection array, which will be an object. Within your callback function, you then access the object as needed.
Pagnito
@Pagnito
Apr 24 2017 01:47
ah i see
Long Nguyen
@longnt80
Apr 24 2017 01:48

hello, I need help with the Challenge: Title Case a Sentence

function titleCase(str) {

   //Split str
   var wordSplit = str.toLowerCase().split(/\s/g);

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

      //Split each word
      var letterSplit = wordSplit[i].split('');

      //Change the firt Letter to Uppercase and Join everything back
      letterSplit[0] = letterSplit[0].toUpperCase();
      wordSplit[i] = letterSplit.join('');
      var newStr = wordSplit.join(' ');
      return newStr;
   }

}

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

the return statement only return the first result from the loop, how can I select the last output of the loop to get the full sentence?

Alros Avellana
@alrosavellana
Apr 24 2017 01:49
hey guys.. question... js arr[i].reduce(function(a,b){return a.concat(b)}),[] } is returning not a function, is it just not possible to reduce an index of an array even through the index itself is an array? I'm on the steamRoller in the intermediate algo's section
CamperBot
@camperbot
Apr 24 2017 01:49
:bulb: to format code use backticks! ``` more info
Ken Haduch
@khaduch
Apr 24 2017 01:51
@longnt80 the return within the for loop ends the loop and the function - you have to figure out how to move that return outside the for loop body.
Justin Chan
@chinesescorpions
Apr 24 2017 01:52
```
Alros Avellana
@alrosavellana
Apr 24 2017 01:52
@longnt80 literally just cut and paste it on the right side of that bracket below it.
Justin Chan
@chinesescorpions
Apr 24 2017 01:52
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  var lookup = {
    "alpha": "Adams",
    "bravo": "Boston",
    "charlie": "Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "foxtrot"
  };

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

// Change this value to test
phoneticLookup("charlie");
help me work it out, pls
Manish Giri
@Manish-Giri
Apr 24 2017 01:53
@chinesescorpions return result;
need to fix that
Long Nguyen
@longnt80
Apr 24 2017 01:54
@khaduch @alrosavellana
I tried to moved it outside the loop but it return some TypeError
Uncaught TypeError: Cannot read property 'split' of undefined
Manish Giri
@Manish-Giri
Apr 24 2017 01:54
lookup is the object from which you need to get the property of the value val and assign to result
@chinesescorpions
Ken Haduch
@khaduch
Apr 24 2017 01:54
@chinesescorpions - set result = after your object, and before your return result; fill in the access of lookup using val as a property. Note that you have to use one of the two techniques of "bracket notation" or "dot notation" - the one that is appropriate with using a variable.
Long Nguyen
@longnt80
Apr 24 2017 01:54
@khaduch @alrosavellana
function titleCase(str) {

   //Split str
   var wordSplit = str.toLowerCase().split(/\s/g);

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

      //Split each word
      var letterSplit = wordSplit[i].split('');

      //Change the firt Letter to Uppercase and Join everything back
      letterSplit[0] = letterSplit[0].toUpperCase();
      wordSplit[i] = letterSplit.join('');
      var newStr = wordSplit.join(' ');

   }
   return newStr;

}

titleCase("I'm a little tea pot");
this one return the error
Ken Haduch
@khaduch
Apr 24 2017 01:55
@longnt80 - note that the scope of newStr is local to your for loop - so you have to fix that. In other words, you cannot access it outside of the for loop, hence the error. (move the wordSplit.join along with the return.)
Long Nguyen
@longnt80
Apr 24 2017 01:58
@khaduch
like this:
function titleCase(str) {

   //Split str
   var wordSplit = str.toLowerCase().split(/\s/g);

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

      //Split each word
      var letterSplit = wordSplit[i].split('');

      //Change the firt Letter to Uppercase and Join everything back
      letterSplit[0] = letterSplit[0].toUpperCase();
      wordSplit[i] = letterSplit.join('');


   }
   var newStr = wordSplit.join(' ');
   return newStr;

}

titleCase("I'm a little tea pot");
?
it still give me the exact same TypeError which point to this part of the code: wordSplit[i].split('');
Justin Chan
@chinesescorpions
Apr 24 2017 02:01
@khaduch @Manish-Giri thank you guys, I got it. Right source code as follows.
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  var lookup = {
    "alpha": "Adams",
    "bravo": "Boston",
    "charlie": "Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "Frank"
  };

  result = lookup[val];

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

// Change this value to test
phoneticLookup("charlie");
CamperBot
@camperbot
Apr 24 2017 02:01
chinesescorpions sends brownie points to @khaduch and @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5273 | @manish-giri |http://www.freecodecamp.com/manish-giri
:star2: 2784 | @khaduch |http://www.freecodecamp.com/khaduch
Long Nguyen
@longnt80
Apr 24 2017 02:02
Here's the Pen @khaduch
Joseph
@revisualize
Apr 24 2017 02:02
Hello.
Justin Chan
@chinesescorpions
Apr 24 2017 02:03
silly questions, :worried: I should read whole code in challenge carefully.
Joseph
@revisualize
Apr 24 2017 02:03
It's all a learning process.
Justin Chan
@chinesescorpions
Apr 24 2017 02:05
@revisualize , for js framework, vue.js or react.js, which do you prefer?
Ken Haduch
@khaduch
Apr 24 2017 02:05
@longnt80 - ah - I missed this - you cannot be processing str.length in your for loop control value - it has to be wordSplit.length because you are dealing with the elements of wordSplit within that loop... sorry that I missed that!
Pagnito
@Pagnito
Apr 24 2017 02:05
@khaduch still cant figure out how to check multiple properties
intcreate
@intcreate
Apr 24 2017 02:06
the js basic part is really hard b
Alfred Conlan
@AlfredConlan
Apr 24 2017 02:06
Can anyone help me with Wherefore Art Thou? This code works for the first 2 tests but not the second 2. No errors. Do I need to put the 'i' pointer in a different place?
function whatIsInAName(collection, source) {
  // What's in a name?
  //var arr = [];
  // Only change code below this line

  let arrSource = Object.keys(source);

  let sortedColl = collection
    .filter(function(event) {
      for(var i in source) {
        return event[arrSource] === source[i];      
      }
  }); 

  // Only change code above this line

  return sortedColl;
}

/* THIS PASSES THE TEST
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
*/
// THIS DOES NOT
whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
Long Nguyen
@longnt80
Apr 24 2017 02:07
@khaduch
oh my god, thank you very much
I didn't pay attention to that part
CamperBot
@camperbot
Apr 24 2017 02:07
longnt80 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2785 | @khaduch |http://www.freecodecamp.com/khaduch
Pagnito
@Pagnito
Apr 24 2017 02:08
@AlfredConlan mine passes the first two, i think u need to make sure that the collection array contains all the properties of source not just one
@AlfredConlan im tryin solve that atm too
Alfred Conlan
@AlfredConlan
Apr 24 2017 02:10
@Pagnito Cool! I can't figure out the right syntax. I see what you mean though.
Ken Haduch
@khaduch
Apr 24 2017 02:10

@Pagnito hint: keys.every( ) and within the callback function check the object for matching properties. Are you using .every()? If you aren't then you could have an inner for loop something like this:

    var matches = 0,
        misses = 0;

    for ( var j = 0; j < sourceKeys.length; j++ ) {
      if (collection[i].hasOwnProperty(sourceKeys[j]) &&
         collection[i][sourceKeys[j]] === source[sourceKeys[j]]) {
        matches++;
      } else {
        misses++;
      }
    }
    if ( matches && !misses ){
      arr.push(collection[i]);
    }

at least that was my initial cut at it. You could also do a single variable to count matches, and then compare that to the length of the keys array.
If you are using .every then some variation of if (collection[i].hasOwnProperty(sourceKeys[j]) && collection[i][sourceKeys[j]] === source[sourceKeys[j]]) { to test the keys for .every

Pagnito
@Pagnito
Apr 24 2017 02:13
@khaduch i dont see where u defined i
or is that code inside the collection loop
Joseph
@revisualize
Apr 24 2017 02:14
@chinesescorpions None of those.
Ken Haduch
@khaduch
Apr 24 2017 02:14
@Pagnito - it's a sample. I have an outer loop that is iterating over collection, and collection[i] is accessing each object. The outer .filter would be doing that for you, if you are using .filter() Or an outer forloop can iterate. As I said, my initial version did not have .filter or .every, just for loops and variables and logic to do the work.
Pagnito
@Pagnito
Apr 24 2017 02:15
ok i see
Alfred Conlan
@AlfredConlan
Apr 24 2017 02:17
@khaduch Should I be using 'every' instead of 'for...in'?
Ken Haduch
@khaduch
Apr 24 2017 02:22
@AlfredConlan - you could try that. I never use for ... in because I'm just not used to it. If you are using it, you have to make sure that you check all of the key/value pairs in the object before making a return. But I think that you are doing something incorrect there, because arrSource is going to be an array, and you cannot do event[arrSource] ?
Alfred Conlan
@AlfredConlan
Apr 24 2017 02:25
@khaduch This code worked before i added the for...in
 let sortedColl = collection
     .filter((event) => 
        event[arrSource] === source[arrSource]);
@khaduch I see what you mean about return
It's exiting the loop, right?
Joseph
@revisualize
Apr 24 2017 02:27
return causes the function to halt and return to the function caller.
Ken Haduch
@khaduch
Apr 24 2017 02:28
@AlfredConlan - return exits everything - returns from the function, ends the loop, etc.
Alfred Conlan
@AlfredConlan
Apr 24 2017 02:28
@khaduch Ok. I'll try to fix that
Pagnito
@Pagnito
Apr 24 2017 02:32
@khaduch i dont get why thi doesnt work
function whatIsInAName(collection,source) {
// What's in a name?
var arr = [];
var filtered = collection.filter(function(item1)
return Object.keys(source)
});
console.log(filtered)
}
Ken Haduch
@khaduch
Apr 24 2017 02:34
@Pagnito - you have an argument item1 to your callback function for filter() - you aren't doing anything with that? You don't even have a properly defined callback function for your .filter() it should be:
collection.filter( function( item1 ) {
    // your filter function code here, doing something with `item1`, most likely
    return "something";
});
Pagnito
@Pagnito
Apr 24 2017 02:36
i dont see whats diffirent about mine tho
i have the same thing, and it returns if it has object keys of source
well thats the idea
oh holdo n
yea the bracket was missing bu yea other than that i dont see whats diffirent
Ken Haduch
@khaduch
Apr 24 2017 02:42
@Pagnito - what value do you think return Object.keys(source) does return?
Pagnito
@Pagnito
Apr 24 2017 02:43
a,b
a27-suryansh
@a27-suryansh
Apr 24 2017 02:43

function largestOfFour(arr) {
  var c =0;
  for (var i=0; i<5; i++) {
  c=arr[i];
       }

  return c;
}
Ken Haduch
@khaduch
Apr 24 2017 02:43
@Pagnito - and what does that actually do in the context of the .filter function?
a27-suryansh
@a27-suryansh
Apr 24 2017 02:43
why is it not looping?
Pagnito
@Pagnito
Apr 24 2017 02:44
i figured when it filters, the callback function would check if the source keys are true in the item1
Ken Haduch
@khaduch
Apr 24 2017 02:44
@AlfredConlan - this might be a spoiler, but I just took the code that you are working with and "fixed" the inner loop so that it will work for the two variable case. DON'T LOOK AT IT IF YOU DON'T WANT A POTENTIAL SPOILER
    .filter(function(event) {
      var countMatch = 0;
      for(var i in source) {
        //console.log(`Value of i in the for...in loop: ${i}`);
        if ( event.hasOwnProperty(i) && event[i] === source[i]){
          countMatch++;
        }
      }
      if (countMatch == arrSource.length) return true;
Justin Chan
@chinesescorpions
Apr 24 2017 02:45
pls help me figure it out
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

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

// Test your code by modifying these values
checkObj("gift");
Ken Haduch
@khaduch
Apr 24 2017 02:46
@Pagnito - you actually have to access the individual items in the sourceKeys in some way - a for loop, or a .every method - something that iterates through the keys.
Pagnito
@Pagnito
Apr 24 2017 02:46
@khaduch i did that initially with for in inside the filter, but then i got the same result
Justin Chan
@chinesescorpions
Apr 24 2017 02:46
both checkObj("gift") and checkObj("pet"), return "Not found"
Pagnito
@Pagnito
Apr 24 2017 02:47

function whatIsInAName(collection,source) {
// What's in a name?
var arr = [];
var filtered = collection.filter(function(item1){

for(var key in item1) {
   return Object.keys(source)
}   

});
console.log(filtered)

John McLellan
@McGooble
Apr 24 2017 02:47
Hey! I'm having some trouble with this basic Escape Sequence challenge, can anyone help provide input as to what im doing wrong? my code: var myStr = "Firstline\n\SecondLine\\rThirdLine";
Pagnito
@Pagnito
Apr 24 2017 02:47
how do ppl always manage to post their code perfectly contained in that dark box
Alfred Conlan
@AlfredConlan
Apr 24 2017 02:47
@khaduch Oh, cool! I thought the for..in needed to be on the outside!
Ken Haduch
@khaduch
Apr 24 2017 02:47
@Pagnito - this is your latest code? :point_up: April 23, 2017 10:47 PM
Pagnito
@Pagnito
Apr 24 2017 02:48
@khaduch kinda, i just put it back
@khaduch it was what i did before the one i showed before that one
Ken Haduch
@khaduch
Apr 24 2017 02:49
@Pagnito - you can see the SPOILER that I posted here :point_up: April 23, 2017 10:44 PM - it's using the for...in within the filter function. Unless you don't want to see it. ;)
Pagnito
@Pagnito
Apr 24 2017 02:49
@khaduch k, il look at it
Alfred Conlan
@AlfredConlan
Apr 24 2017 02:50
@khaduch No, the filter is on the outside still. I didn't think of doing that with return!
John McLellan
@McGooble
Apr 24 2017 02:52
When I type an escape sequence is this the correct syntax? "Firstline\nSecondline"
Ken Haduch
@khaduch
Apr 24 2017 02:52
@AlfredConlan - the .filter is iterating through the items in the collection. "Inside" for each object in the collection, you are running the loop to check that each key/value in the source has a match in the collection - so I'm counting matching key/value pairs, and if the length of that matches the length of arrSource.length, then return true; which keeps that element in the array. If you don't return true; implicitly returns undefined, so that's not true, so the element gets tossed.
@McGooble if you want to put a newline in there, yes. You have to make sure (for this challenge) that you keep the same spelling of the other words - FirstLine and SecondLine - that extra capital letter in the middle.
Dalton Escoe
@Alenero129
Apr 24 2017 02:53
Hello
Alfred Conlan
@AlfredConlan
Apr 24 2017 02:54
@khaduch Thank you! And since I have been working on this since yesterday, I don't mind the Spoiler :smile:
CamperBot
@camperbot
Apr 24 2017 02:54
alfredconlan sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2786 | @khaduch |http://www.freecodecamp.com/khaduch
Dalton Escoe
@Alenero129
Apr 24 2017 02:54
I need some help with concatenating strings and variables
Alfred Conlan
@AlfredConlan
Apr 24 2017 02:55
Thank you @Pagnito
CamperBot
@camperbot
Apr 24 2017 02:55
alfredconlan sends brownie points to @pagnito :sparkles: :thumbsup: :sparkles:
:cookie: 220 | @pagnito |http://www.freecodecamp.com/pagnito
Ken Haduch
@khaduch
Apr 24 2017 02:55
@AlfredConlan - you should try to figure out how to use .every() as the inner loop, or rather, in place of the inner loop. Or tuck that challenge away for another time - I initially solved it with two nested for loops, until I started becoming more familiar with the higher-order functions.
You're welcome - good luck with the next challenges!
Dalton Escoe
@Alenero129
Apr 24 2017 02:55

```function weatherInfo(){
var lat, lon, acc;
navigator.geolocation.getCurrentPosition(function(location){
lat=location.coords.latitude;
lon=location.coords.longitude;
acc=location.coords.accuracy;
});

var loc='api.openweathermap.org/data/2.5/weather?lat={'+lat+'}&lon={'+lon+'}';

console.log(loc);

};```
lat, lon and acc are assigned values. I can see them when I console log it but when I concat them in the string 'loc', it shows as undefined. Anyone knows why?

Moisés Man
@moigithub
Apr 24 2017 02:58
geolocation method is ASYNC .. mean it gonna be executed later (not immediatelly) @Alenero129
on the meanwhile all the rest of code keep executing
Jason Luboff
@JLuboff
Apr 24 2017 02:58
@Alenero129 Geolocation runs as an asynchronous code block, so while its running, loc is already given the undefined values
@Alenero129 Easiest fix is to keep all your code inside the geolocation code block
Ken Haduch
@khaduch
Apr 24 2017 02:58
@Alenero129 - navigator.geolocation.getCurrentPosition() is an asynchronous method - it returns the values "after some time passes" - not in sync with the execution of your code. So the geolocation is called, then the loc variable is created, but the return values from the location are not defined.
Alfred Conlan
@AlfredConlan
Apr 24 2017 02:59
@khaduch I will try it with .every() instead of for..in. I've been solving all the challenges with nested for loops, but I'm trying to move to higher-order functions. The more I learn now, the better my future challenges with go :+1:
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 02:59
Hey can someone tell my how the total would be 20?
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line
var total = 0;
for (var i = 0; i < myArr.length; i++){
  total += myArr[i];
}
Moisés Man
@moigithub
Apr 24 2017 02:59
2+3+4+5+6 = 20
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 03:00
but why is it adding the numbers?
i never told it to?
Jason Luboff
@JLuboff
Apr 24 2017 03:00
@Rafewey You are.. total += myArr[i]
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 03:00
ohhhhhh
Hey guys, I'll be right back while I go kill myself due to my massive brain fart.
Thanks though.
khaduch @khaduch - now that more reinforcements have come along, time to hit the road... happy coding everyone! Good night all...
And @Rafewey - go easy on yourself - you're learning something new! :)
Dalton Escoe
@Alenero129
Apr 24 2017 03:02
@JLuboff I'll give it a try. @khaduch
Much thanks for your response
CamperBot
@camperbot
Apr 24 2017 03:02
alenero129 sends brownie points to @jluboff and @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 1589 | @jluboff |http://www.freecodecamp.com/jluboff
:star2: 2787 | @khaduch |http://www.freecodecamp.com/khaduch
Dalton Escoe
@Alenero129
Apr 24 2017 03:04
@JLuboff So the value won't show immediately, but that means that it won't be assigned as well even if I put it in the block?
yofri
@yofriadi
Apr 24 2017 03:05

guys i have no idea to solve
truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length)

should return "A-tisket a-tasket A green and yellow basket".

heres my code

function truncateString(str, num) {

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

truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length);
no problem it solved
} else {
    return str;
  }
Jason Luboff
@JLuboff
Apr 24 2017 03:06
@Alenero129 It will. Since it won't move onto the next portion of code until its portion has completed (if its all in the same code block)
Devon Thomas
@UmbraLegacy
Apr 24 2017 03:06

Hello, you beautiful people. Quick question, in regards to Arguments Optional.
Context:
I'm supposed to return a function if a single argument is passed. That returned function may be called with another argument. Otherwise, I'm to return undefined.

Question:
How can I return undefined if the returned function isn't being invoked?

Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 03:09

function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (var i = 0; i < arr.length; i++){
    for (var j = 0; i < arr[i].length; j++){
      product *= arr[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]]);
Can someone help me here?
a27-suryansh
@a27-suryansh
Apr 24 2017 03:09

@JLuboff


function largestOfFour(arr) {
  var c=0;
  var z;
  for (var i=0; i<=arr.length-1; i++) {
     z=arr[i];
     if(z>c) {
    c=arr[i];
    }

  }

  return c;
}

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

why is it not working?

Justin Chan
@chinesescorpions
Apr 24 2017 03:10
guys, in Chrome Dev Tool console,
// Setup
var myStorage = {
  "car": {
    "inside": {
      "glove box": "maps",
      "passenger seat": "crumbs"
     },
    "outside": {
      "trunk": "jack"
    }
  }
};

// Only change code below this line

var gloveBoxContents = myStorage.car["inside"]["glove box"]; // Change this line
undefined
gloveBoxContents;
"maps"
a27-suryansh
@a27-suryansh
Apr 24 2017 03:10
Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.
Gulsvi
@gulsvi
Apr 24 2017 03:10
@a27-suryansh arr[i] in your loop will output the sub arrays, not individual numbers
Justin Chan
@chinesescorpions
Apr 24 2017 03:10
but in freecodecamp, it is like
// Setup
var myStorage = {
  "car": {
    "inside": {
      "glove box": "maps",
      "passenger seat": "crumbs"
     },
    "outside": {
      "trunk": "jack"
    }
  }
};

// Only change code below this line

var gloveBoxContents = myStorage.car["inside"]["glove box"]; // Change this line
Devon Thomas
@UmbraLegacy
Apr 24 2017 03:11
@Yofri , can you give another example and solution?
Justin Chan
@chinesescorpions
Apr 24 2017 03:11
it really works, but freecodecamp still give me a alert
zacharydylan
@zacharydylan
Apr 24 2017 03:11
@Rafewey I think you just messed up a variable in your second loop.
yofri
@yofriadi
Apr 24 2017 03:12
@UmbraLegacy i dont, i just passed it
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 03:12
@zacharydylan which variable?
a27-suryansh
@a27-suryansh
Apr 24 2017 03:12
@SkyCoder01 thanks for answering
CamperBot
@camperbot
Apr 24 2017 03:12
a27-suryansh sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
:star2: 1157 | @skycoder01 |http://www.freecodecamp.com/skycoder01
Gulsvi
@gulsvi
Apr 24 2017 03:12
Sure @a27-suryansh Hope it makes sense... you're checking if [4,5,1,3] > 0 (for example) on that first loop. You need to loop again on each sub array
Devon Thomas
@UmbraLegacy
Apr 24 2017 03:12
@Yofri , function truncateString(str, num) { if (str.length > num){ return str.slice(0, num) + '...'; } return str; }
Does it satisfy your needs?
zacharydylan
@zacharydylan
Apr 24 2017 03:13
@Rafewey you compare against i as opposed to j.
a27-suryansh
@a27-suryansh
Apr 24 2017 03:13
@SkyCoder01 yes i got it i think
Dalton Escoe
@Alenero129
Apr 24 2017 03:13
@JLuboff I'm still seeing undefined though. My knowledge of AJAX is really fuzzy.
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 03:13
@zacharydylan ohhhhhhhhhhhhh
ty @zacharydylan
CamperBot
@camperbot
Apr 24 2017 03:13
rafewey sends brownie points to @zacharydylan :sparkles: :thumbsup: :sparkles:
:cookie: 308 | @zacharydylan |http://www.freecodecamp.com/zacharydylan
zacharydylan
@zacharydylan
Apr 24 2017 03:13
@Rafewey np.
Jason Luboff
@JLuboff
Apr 24 2017 03:13
@Alenero129 Show your updated code
yofri
@yofriadi
Apr 24 2017 03:14
@UmbraLegacy there is 3 condition, two of them is ... is added to the length if > 3 otherwise it is not added
Dalton Escoe
@Alenero129
Apr 24 2017 03:14
@JLuboff It worked. You were right.
Jason Luboff
@JLuboff
Apr 24 2017 03:16
:+1:
Pagnito
@Pagnito
Apr 24 2017 03:17
@khaduch hey i ended up finding this on google

@khaduch function whatIsInAName(collection, source) {
// "What's in a name? that which we call a rose
// By any other name would smell as sweet.”
// -- by William Shakespeare, Romeo and Juliet
var srcKeys = Object.keys(source);

var filtered = collection.filter(function (obj) {
return srcKeys.every(function (key) {
return obj.hasOwnProperty(key) && obj[key] === source[key];
});
});
console.log(filtered)
}

but im still not sure how it works
Devon Thomas
@UmbraLegacy
Apr 24 2017 03:18
I need this to return undefined if no argument is passed to the returned function.
function addTogether() {
    var x = arguments[0], y = arguments[1];

    if (y === undefined) {
        var f = function(){
            var y = arguments[0];

            if (y === undefined) {
                return undefined;
            } else if (typeof y !== "number") {
                return undefined;
            }
            return x + y;
        };
        return f;
    } else if ((typeof x !== "number") | (typeof y !== "number")) {
        return undefined; 
    }
    return x + y;
}

var result = addTogether(2); // Return undefined.
var result = addTogether(2)(3); // Return 6.
var result = addTogether(2, 4); // Return 8.
@Yofri , can you send me a link to the page. It'll be faster to help you.
@LuisJaquez , no one will help you unless you properly format your post. Go back and edit it.
Luis Jaquez
@LuisJaquez
Apr 24 2017 03:20
I dont know how to do that
yofri
@yofriadi
Apr 24 2017 03:21
@UmbraLegacy no, you take me wrong, i just solved the test myself, but thanks for the response, i got another task here to solve, maybe you can help
CamperBot
@camperbot
Apr 24 2017 03:21
yofri sends brownie points to @umbralegacy :sparkles: :thumbsup: :sparkles:
:cookie: 283 | @umbralegacy |http://www.freecodecamp.com/umbralegacy
Pagnito
@Pagnito
Apr 24 2017 03:21
hey how do ppl post code on here perfectly contained in the box?
Jason Luboff
@JLuboff
Apr 24 2017 03:21
@Pagnito
```
shift+enter for new line, paste code, shift+enter for new line
```
Devon Thomas
@UmbraLegacy
Apr 24 2017 03:21
Open the Markdown Help, located to the right of the text box.
Pagnito
@Pagnito
Apr 24 2017 03:21
alot of time mine will contain half the code in the box and half not, or not at all
Joseph
@revisualize
Apr 24 2017 03:21
Hello.
Pagnito
@Pagnito
Apr 24 2017 03:22
hold ima just test this out

function whatIsInAName(collection,source) {
// What's in a name?
var arr = [];
var keys = Object.keys(source);
collection.forEach(function(item1, index){

})
}

lol hold on ima get this, i didnt understand what u meant with shift enter, with every line of code?? ima try the markdown right now

function whatIsInAName(collection,source) {
// What's in a name?
var arr = [];
var keys = Object.keys(source);
collection.forEach(function(item1, index){

})
}

Joseph
@revisualize
Apr 24 2017 03:23
If anyone wants assistance with any of the beginner challenges (beginning JavaScript Algorithms (except Seek and Destroy) downward.) I'm willing to jump in a live / webcam / pair programming session.
Pagnito
@Pagnito
Apr 24 2017 03:24

function whatIsInAName(collection,source) {
// What's in a name?
var arr = [];
var keys = Object.keys(source);
collection.forEach(function(item1, index){

})
}

Jason Luboff
@JLuboff
Apr 24 2017 03:24
@Pagnito No..you put three ``` then shift+enter, paste your code, shift+enter and three moire ```
The backticks just need to be on their own line
Devon Thomas
@UmbraLegacy
Apr 24 2017 03:24
You can edit your previous posts. Please correct their formating, rather than reposting.
bin546882521
@bin546882521
Apr 24 2017 03:25
Use point and square brackets to access myStorage?what is mean?myStorage.car["inside"]["glove box"];
Pagnito
@Pagnito
Apr 24 2017 03:25
ooh, how do i type in those ticks
jaganjaan
@jaganjaan
Apr 24 2017 03:25
how to run a function when page over loading
Joseph
@revisualize
Apr 24 2017 03:25
@bin546882521 turn inside into dot notation.
zacharydylan
@zacharydylan
Apr 24 2017 03:26
@Pagnito Usually above tab.
Joseph
@revisualize
Apr 24 2017 03:26
@jaganjaan Page over loading?
Jason Luboff
@JLuboff
Apr 24 2017 03:26
@Pagnito US keyboard its the key above tab
Pagnito
@Pagnito
Apr 24 2017 03:26
oooh shit, i never used it before lol
k ima try it
jaganjaan
@jaganjaan
Apr 24 2017 03:27
when page first load onclick function execute???
bin546882521
@bin546882521
Apr 24 2017 03:28
@revisualize You are right,Thanks,It's been bothering me for a long time。
CamperBot
@camperbot
Apr 24 2017 03:28
bin546882521 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3821 | @revisualize |http://www.freecodecamp.com/revisualize
Gulsvi
@gulsvi
Apr 24 2017 03:28
@jaganjaan window.onload = function() {} works a lot of the time, with jQuery use $(document).ready(function() {})
Pagnito
@Pagnito
Apr 24 2017 03:28
i cant click send lol after pressing shift enter
ooh nvm i got it
Devon Thomas
@UmbraLegacy
Apr 24 2017 03:28
Also, for future reference, if you're going to ask for help in regards to a question, post your code (properly) and a link to the question. It's easier to get context on the problem.
Gulsvi
@gulsvi
Apr 24 2017 03:28
Ctrl+Enter Pagnito :)
Pagnito
@Pagnito
Apr 24 2017 03:29
function whatIsInAName(collection,source) {
  // What's in a name?
  var arr = [];
  var keys = Object.keys(source);
  collection.forEach(function(item1, index){


  })
}
sweet i did it lol
Jason Luboff
@JLuboff
Apr 24 2017 03:29
@Pagnito There you go
Gulsvi
@gulsvi
Apr 24 2017 03:29
:clap:
Pagnito
@Pagnito
Apr 24 2017 03:29
thanks
woop woop
jaganjaan
@jaganjaan
Apr 24 2017 03:29
@SkyCoder01 thanks
Gulsvi
@gulsvi
Apr 24 2017 03:29
ヽ(^o^)ノ
Devon Thomas
@UmbraLegacy
Apr 24 2017 03:29
@Pagnito , what is your question?
Joseph
@revisualize
Apr 24 2017 03:29
@Pagnito Your function is returning undefinded
Pagnito
@Pagnito
Apr 24 2017 03:30
@UmbraLegacy i was just learning how to post code inside the box
@revisualize iwas just learning to post code properly
a27-suryansh
@a27-suryansh
Apr 24 2017 03:30
function largestOfFour(arr) {
  var c=0;
  var z;
  for (var i=0; i<=arr.length-1; i++) {
         z=arr[i];
    for (var j=0; j<=arr[i].length-1; j++) {
      x=arr[i][j];
        }
     if(z>c) {
    c=arr[i][j];
    }

  }

  return c;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
@SkyCoder01
why is it returning 0
Joseph
@revisualize
Apr 24 2017 03:30

If you are posting code that is large, Please use Gist - https://gist.github.com/ then please paste the link here.
...
How to do code block format: ..... PLEASE try with a small block of code before you try to make a bigger one.
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code
```js [SHIFT+ENTER]
// your code here
``` [CTRL+ENTER or CMD+ENTER to send]
Please do not confuse `s with 's.
Also note that the ```s need to each be on their own lines
The ` key can usually be found on most keyboards up next to the 1 key.
If you hit SHIFT+` it will give you the ~.
Example:
```
code
```
...
Output:

var code = undefined;

...
You can also do inline code formatting:
A string of text with a `variable` or `other bit of code`.
Output:
A string of text with a variable or other bit of code.

Luis Jaquez
@LuisJaquez
Apr 24 2017 03:31
Heres my code
function golfScore(par, strokes) {
  // Only change code below this line
  if (par == 1){
    return "Hole-in-one";
  }
  else if ( strokes <= par -2){
    return "Eagle";
  }
  else if (par - 1){
    return "Birdie";
  }
  else if (par){
    return "Par";
  }
  else if (par + 1){
    return "Bogey";
  }
  else if (par + 2){
    return "Double Bogey";
  }
  else if (strokes >= par + 3)
  return "Go Home!";

  // Only change code above this line
}

// Change these values to test
golfScore(5, 4);
Sorry for the duplicate
Joseph
@revisualize
Apr 24 2017 03:31

@LuisJaquez

  if (par == 1){
    return "Hole-in-one";
  }

This is incorrect.

Devon Thomas
@UmbraLegacy
Apr 24 2017 03:32
@LuisJaquez , can you send the link to the question. I need context.
Joseph
@revisualize
Apr 24 2017 03:32
@LuisJaquez You can edit posts.
Gulsvi
@gulsvi
Apr 24 2017 03:32
@a27-suryansh Because z is always equal to an array, so z is never greater than c (an array can't be greater than or less than a number)
Joseph
@revisualize
Apr 24 2017 03:32
@LuisJaquez All of your if conditions are incorrect.
Gulsvi
@gulsvi
Apr 24 2017 03:32
z remains = 0 as you have it defined in the beginning
@LuisJaquez You can press the up arrow to edit your comment
a27-suryansh
@a27-suryansh
Apr 24 2017 03:33
why is it not returning anything if i change z to x @SkyCoder01 ?
Joseph
@revisualize
Apr 24 2017 03:33
@a27-suryansh I suggest running your code through www.pythontutor.com/javascript.html
a27-suryansh
@a27-suryansh
Apr 24 2017 03:34
why? @revisualize
Joseph
@revisualize
Apr 24 2017 03:34
@a27-suryansh Because you have several issues.
Gulsvi
@gulsvi
Apr 24 2017 03:34
@a27-suryansh With these problems, and as the more challenging ones coming up it helps to see what the values are at each step of your code. That website from @revisualize is a good tool to help with it. I used http://codepen.io and added lots of console.log() statements, which is another option.
Luis Jaquez
@LuisJaquez
Apr 24 2017 03:34
@SkyCoder01 Thanks
CamperBot
@camperbot
Apr 24 2017 03:34
luisjaquez sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
:star2: 1158 | @skycoder01 |http://www.freecodecamp.com/skycoder01
Gulsvi
@gulsvi
Apr 24 2017 03:35
@LuisJaquez No problem :) I use it all the time (fat fingers lol)
I'm always making typos...
Luis Jaquez
@LuisJaquez
Apr 24 2017 03:35
@revisualize I did now
a27-suryansh
@a27-suryansh
Apr 24 2017 03:35
@revisualize it's a great tool!
Devon Thomas
@UmbraLegacy
Apr 24 2017 03:36

I need this to return undefined if no argument is passed to the returned function.

function addTogether() {
    var x = arguments[0], y = arguments[1];

    if (y === undefined) {
        var f = function(){
            var y = arguments[0];

            if (y === undefined) {
                return undefined;
            } else if (typeof y !== "number") {
                return undefined;
            }
            return x + y;
        };
        return f;
    } else if ((typeof x !== "number") | (typeof y !== "number")) {
        return undefined; 
    }
    return x + y;
}

var result = addTogether(2); // Return undefined.
var result = addTogether(2)(3); // Return 6.
var result = addTogether(2, 4); // Return 8.

Can anyone help with this?

Aizaz Shahid
@aizazshahid
Apr 24 2017 03:38
@UmbraLegacy what is the challenge name ??
a27-suryansh
@a27-suryansh
Apr 24 2017 03:38
@revisualize what's the issue with this line x=arr[i][j];
Joseph
@revisualize
Apr 24 2017 03:39
@a27-suryansh outside of the for loop x is always the last element in the array.
Luis Jaquez
@LuisJaquez
Apr 24 2017 03:39
@UmbraLegacy Golf Code
Joseph
@revisualize
Apr 24 2017 03:40
@a27-suryansh And x only becomes elements in the for loop in the for loop
@a27-suryansh Do you want an example of what I'm talking about?
Devon Thomas
@UmbraLegacy
Apr 24 2017 03:42
@LuisJaquez ,
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!";
    }
}

// Change these values to test
golfScore(5, 4);
Aizaz Shahid
@aizazshahid
Apr 24 2017 03:42
@UmbraLegacy i think you don't need much coding for that !!
a27-suryansh
@a27-suryansh
Apr 24 2017 03:42
@revisualize yes
Rhys
@105ron
Apr 24 2017 03:43
Could use a JavaScript object
Joseph
@revisualize
Apr 24 2017 03:43
@a27-suryansh I'm going to break the example down to something smaller.
Aizaz Shahid
@aizazshahid
Apr 24 2017 03:43
:point_up: April 24, 2017 8:36 AM talking about that .
Devon Thomas
@UmbraLegacy
Apr 24 2017 03:43
@forwebtech , can you be more specific?
Aizaz Shahid
@aizazshahid
Apr 24 2017 03:45
ok am showing you my code for adding numbers !
also comments are their !
Rhys
@105ron
Apr 24 2017 03:46
I don't understand the arguments optional exercise
Luis Jaquez
@LuisJaquez
Apr 24 2017 03:46
@UmbraLegacy Thanks for the help!!! Sorry for the inconvenience.
CamperBot
@camperbot
Apr 24 2017 03:46
luisjaquez sends brownie points to @umbralegacy :sparkles: :thumbsup: :sparkles:
:cookie: 284 | @umbralegacy |http://www.freecodecamp.com/umbralegacy
a27-suryansh
@a27-suryansh
Apr 24 2017 03:47
@revisualize i have understood why x returns 1
function largestOfFour(arr) {
  var c=0;
  var z;

  for (var i=0; i <= arr.length-1; i++) {
  z=arr[i];

    for (var j=0; j <= arr[i].length-1; j++) {
    x = arr[i][j];

      if(x>c) {
       c = arr[i][j];

      } 

    }

  }

  return c;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
why is c returning 1001 and not 1
it seems @revisualize is not available @forwebtech any idea why my code is doing that?
Joseph
@revisualize
Apr 24 2017 03:48

@a27-suryansh You have this code:

    z=arr[i];
    for (var j=0; j<=arr[i].length-1; j++) {
      x=arr[i][j];
        }
     if(z>c) {
    c=arr[i][j];
    }

okay, Let me break this down to something smaller.

var arr = [[40,30,20,10]];
var c = 0
var i = 0;
z = arr[i]; // [40,30,20,10]
for (var j = 0; j < arr[i].length; j++)
      x= arr[i][j];
 }
if (z > c) {
     c = arr[i][j];
  }

arr is an array with a single sub-array as an element.
okay. So, c starts out as 0.

I was typing.
But, whatever.
a27-suryansh
@a27-suryansh
Apr 24 2017 03:49
@revisualize c is returnig 1 coz array is like this arr[3][3] right?
Joseph
@revisualize
Apr 24 2017 03:50
@a27-suryansh First off. Your variable names suck.
a27-suryansh
@a27-suryansh
Apr 24 2017 03:50
@revisualize i know
Rhys
@105ron
Apr 24 2017 03:51
@a27-suryansh thanks for the variable names
CamperBot
@camperbot
Apr 24 2017 03:51
105ron sends brownie points to @a27-suryansh :sparkles: :thumbsup: :sparkles:
revisualize @revisualize goes AFK. Laundry.
CamperBot
@camperbot
Apr 24 2017 03:51
:warning: @a27-suryansh's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
Aizaz Shahid
@aizazshahid
Apr 24 2017 03:51
@a27-suryansh you can simplify it by simply first doint sort those arrays
a27-suryansh
@a27-suryansh
Apr 24 2017 03:51
@105ron why ?
Rhys
@105ron
Apr 24 2017 03:51
afk house keeping
Aizaz Shahid
@aizazshahid
Apr 24 2017 03:51
in descending !
like [ [5,4,3,2,1], [10,9,8] .... ], then just get their first element of four :)
a27-suryansh
@a27-suryansh
Apr 24 2017 03:52
@forwebtech nice
@forwebtech but why is it returning 1001 instead of 1
Aizaz Shahid
@aizazshahid
Apr 24 2017 03:53
ok let me read !
Joseph
@revisualize
Apr 24 2017 03:53
@a27-suryansh Did you use pythontutor again?
a27-suryansh
@a27-suryansh
Apr 24 2017 03:53
no
Joseph
@revisualize
Apr 24 2017 03:53
Why not?
a27-suryansh
@a27-suryansh
Apr 24 2017 03:53
I am not understanding that tool
Joseph
@revisualize
Apr 24 2017 03:53
@a27-suryansh It allows you to walk through your code step by step.
Some Random Guy
@SomeRandomGuy0
Apr 24 2017 03:54
Could someone help me with "Construct JavaScript Objects with Functions." I am having a hard time understanding this. variable
Joseph
@revisualize
Apr 24 2017 03:54
back to being AFK for me. I need to switch out my laundry.
a27-suryansh
@a27-suryansh
Apr 24 2017 03:54
it is stopping the execution at this line x = arr[i][j];
Khoa Le
@Zacele
Apr 24 2017 03:54

function rot13(str) { // LBH QVQ VG!
   var chr=  str.split("");
  var newChr=[];
  var newStr = " ";
  var index = 0;
   for (var i =0 ; i<chr.length;i++){
     if(chr[i] ===/([A-M])/g){
      index= chr[i].charCodeAt(i) + 13;
     }
     else if(chr[i] ===/([N-Z])/g){
       index= chr[i].charCodeAt(i) - 13;        
     } else {

     }
    newChr.push(index);
   }

  return newChr;
}


// Change the inputs below to test
rot13("SERR PBQR PNZC");
Joseph
@revisualize
Apr 24 2017 03:54
@a27-suryansh Show me your code
Khoa Le
@Zacele
Apr 24 2017 03:54
here is my code for the "Caesars Cipher" challenge
could anyone explain to me why my newChr always return [0,0,0...0]
Aizaz Shahid
@aizazshahid
Apr 24 2017 03:55
@a27-suryansh you are getting 1001, its correct by your logic
a27-suryansh
@a27-suryansh
Apr 24 2017 03:55
function largestOfFour(arr) {
  var c=0;
  var z;

  for (var i=0; i <= arr.length-1; i++) {
  z=arr[i];

    for (var j=0; j <= arr[i].length-1; j++) {
    x = arr[i][j];

      if(x>c) {
       c = arr[i][j];

      } 

    }

  }

  return c;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Joseph
@revisualize
Apr 24 2017 03:55
@a27-suryansh There is 0 reason for your code to halt if you are not doing a return statement.
Aizaz Shahid
@aizazshahid
Apr 24 2017 03:55
@a27-suryansh because you are just checking into your whole array for the biggest value !
Joseph
@revisualize
Apr 24 2017 03:55
@a27-suryansh Do you realize that you're supposed to be returning an array?
a27-suryansh
@a27-suryansh
Apr 24 2017 03:56
x = arr[i][j]; @revisualize stopping here
@revisualize i will do that later just experimenting with my code
Aizaz Shahid
@aizazshahid
Apr 24 2017 03:56
@a27-suryansh do you know your return should be array ??
Joseph
@revisualize
Apr 24 2017 03:56
@a27-suryansh because ReferenceError: x is not defined
Some Random Guy
@SomeRandomGuy0
Apr 24 2017 03:56
Could someone help me with "Construct JavaScript Objects with Functions." I am having a hard time understanding this. variable

var Car = function() {
  this.wheels = 4;
  this.engines = 1;
  this.seats = 5;
};

// Only change code below this line.

var MotorBike = function() {
  this.wheels = 4;
  this.engines= 1;
  this.seats = 2;
};
Joseph
@revisualize
Apr 24 2017 03:56
You haven't defined the variable x
Aizaz Shahid
@aizazshahid
Apr 24 2017 03:57
@a27-suryansh your logic is fine because its finding the longest element from the whole array !
Joseph
@revisualize
Apr 24 2017 03:57
@a27-suryansh You need to declare the x variable.
anderson
@anderson2825
Apr 24 2017 03:57

function titleCase(str) {
var strarry=str.split(' ');
for(var i=0;i<strarry.length;i++){
var restrd=strarry[i][0].toUpperCase();
strarry[i][0].replace(restrd);
var resddd=strarry[i].replace(strarry[i][0],restrd);
console.log(resddd);
};

console.log(strarry);
}

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

titleCase("I'm a little tea pot") should return a string.
titleCase("I'm a little tea pot") should return "I'm A Little Tea Pot".
titleCase("sHoRt AnD sToUt") should return "Short And Stout".
titleCase("HERE IS MY HANDLE HERE IS MY SPOUT") should return "Here Is My Handle Here Is My Spout".

I can convert the case, how can the conversion into the array after it?

Aizaz Shahid
@aizazshahid
Apr 24 2017 03:57
:bulb: To format your code, please follow, Format code
Joseph
@revisualize
Apr 24 2017 03:57
@a27-suryansh There is no var x anywhere in your code.
a27-suryansh
@a27-suryansh
Apr 24 2017 03:57
@revisualize @forwebtech
got it
Joseph
@revisualize
Apr 24 2017 03:57
@a27-suryansh You have to declare variables if you want to use them.
a27-suryansh
@a27-suryansh
Apr 24 2017 03:58
Yes i know just forgot to declare this one
Joseph
@revisualize
Apr 24 2017 03:58
Okay. Serious laundry time for me.
a27-suryansh
@a27-suryansh
Apr 24 2017 03:59
ok Thanks for your help @revisualize
CamperBot
@camperbot
Apr 24 2017 03:59
a27-suryansh sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3822 | @revisualize |http://www.freecodecamp.com/revisualize
a27-suryansh
@a27-suryansh
Apr 24 2017 03:59
@forwebtech
Chasls
@Chasls
Apr 24 2017 03:59
hey all
a27-suryansh
@a27-suryansh
Apr 24 2017 03:59
how do i compare it with rest of the arrays
Chasls
@Chasls
Apr 24 2017 03:59
I need help with lesson 155.
Devon Thomas
@UmbraLegacy
Apr 24 2017 03:59
@a27-suryansh ,
function largestOfFour(arrays) {
    var result = [];
    for (var list = 0, arr = arrays[list]; list < arrays.length; arr = arrays[++list]) {
        console.log("arr:", arr);
        var largest = arr[0];
        for (var index = 0, value = arr[index]; index < arr.length; value = arr[++index]){
            console.log("\tval:", value);
            if (value > largest) {
                largest = value;
            }
        }
        result.push(largest);

    }
    return result;
}

console.log(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]));
Aizaz Shahid
@aizazshahid
Apr 24 2017 03:59
@revisualize but in JS, they will not make errors if don't use var keyword, @a27-suryansh
Chasls
@Chasls
Apr 24 2017 03:59
I need help with lesson 155
Joseph
@revisualize
Apr 24 2017 04:00
@forwebtech But, www.pythontutor.com requires that variables are declared.
anderson
@anderson2825
Apr 24 2017 04:00
pls help me lesson 241
Aizaz Shahid
@aizazshahid
Apr 24 2017 04:00
@revisualize yes its just in JS
you are right as well :)
Joseph
@revisualize
Apr 24 2017 04:00
Aizaz Shahid
@aizazshahid
Apr 24 2017 04:00
@a27-suryansh didn't get you ??
as you know you have nested array so make an array instead of just one variable like you did above c = 0 => c = []
Khoa Le
@Zacele
Apr 24 2017 04:01
yo
could anyone help me out
Aizaz Shahid
@aizazshahid
Apr 24 2017 04:02
@a27-suryansh and just use that array to store the biggest value : )
Bluestin
@Bluestin
Apr 24 2017 04:02
Hey guys, how can I show my code here?
Aizaz Shahid
@aizazshahid
Apr 24 2017 04:03
@a27-suryansh for its index you can use c[c.length] !
a27-suryansh
@a27-suryansh
Apr 24 2017 04:03
@forwebtech i am totally confused right now let me analyze what is going on
Bluestin
@Bluestin
Apr 24 2017 04:03
var code = "formatted";
Devon Thomas
@UmbraLegacy
Apr 24 2017 04:03
@a27-suryansh , I already gave you a working solution.
Joseph
@revisualize
Apr 24 2017 04:04

If you are posting code that is large, Please use Gist - https://gist.github.com/ then please paste the link here.
...
How to do code block format: ..... PLEASE try with a small block of code before you try to make a bigger one.
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code
```js [SHIFT+ENTER]
// your code here
``` [CTRL+ENTER or CMD+ENTER to send]
Please do not confuse `s with 's.
Also note that the ```s need to each be on their own lines
The ` key can usually be found on most keyboards up next to the 1 key.
If you hit SHIFT+` it will give you the ~.
Example:
```
code
```
...
Output:

var code = undefined;

...
You can also do inline code formatting:
A string of text with a `variable` or `other bit of code`.
Output:
A string of text with a variable or other bit of code.

Aizaz Shahid
@aizazshahid
Apr 24 2017 04:04
@a27-suryansh come to private chat !
Bluestin
@Bluestin
Apr 24 2017 04:04
var code = "formatted";
Aizaz Shahid
@aizazshahid
Apr 24 2017 04:04
i will explain you from start !
a27-suryansh
@a27-suryansh
Apr 24 2017 04:04
@UmbraLegacy But i want to solve it on my own
Bluestin
@Bluestin
Apr 24 2017 04:04
Oh I get it thank you help system
a27-suryansh
@a27-suryansh
Apr 24 2017 04:04
ok @forwebtech
Chasls
@Chasls
Apr 24 2017 04:06
hey all.. I neeed help with lesson 155. in javascript.
Word Blank
Devon Thomas
@UmbraLegacy
Apr 24 2017 04:09
@forwebtech , did you end up elaborating on the solution to my issue?
Aizaz Shahid
@aizazshahid
Apr 24 2017 04:09
@UmbraLegacy sorry for late, but send it when done !
Mohammed Saifuddin
@acesaif
Apr 24 2017 04:10
hello ... i have a small issue with my quote machine ... here is my link
http://codepen.io/acesaif/pen/LyVRMW
please let me know if this fetching new quote in ur system
thank u
in my system this is fetching new quote ... so seeking help
Khoa Le
@Zacele
Apr 24 2017 04:11
hey guys
Mohammed Saifuddin
@acesaif
Apr 24 2017 04:11
*is not
Khoa Le
@Zacele
Apr 24 2017 04:12

function rot13(str) { // LBH QVQ VG!
   var chr=  str.split("");
  var newChr=[];
  var newStr = " ";
  var index = 0;
   for (var i =0 ; i<chr.length;i++){
     if(chr[i] ===/([A-M])/g){
      index= chr[i].charCodeAt(i) + 13;
     }
     else if(chr[i] ===/([N-Z])/g){
       index= chr[i].charCodeAt(i) - 13;        
     } else {

     }
    newChr.push(index);
   }

  return newChr;
}


// Change the inputs below to test
rot13("SERR PBQR PNZC");
the Cipher challenge
why is the newChr array keep return [0,0,0,....0]
Joni petriashvili
@Jonhnwhantcoding
Apr 24 2017 04:13
var count = 0;

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

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

  // 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');
would you guys please help me why it's not working/
?
Khoa Le
@Zacele
Apr 24 2017 04:16
what is the console tell you ?
Joni petriashvili
@Jonhnwhantcoding
Apr 24 2017 04:17
here is new code
var count = 0;

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

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

  // 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');
because 7,8,9 doesn't make sense
console says 0 bet in this case
Khoa Le
@Zacele
Apr 24 2017 04:17
you could do that
Joni petriashvili
@Jonhnwhantcoding
Apr 24 2017 04:18
ok
Khoa Le
@Zacele
Apr 24 2017 04:18
or you could leave out those last case as default
saving you time
Joni petriashvili
@Jonhnwhantcoding
Apr 24 2017 04:18
in Switch statment ?
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:
      count+=0;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count--;
      break;

  }
  if(count >= 0){
    return  count + " Hold";
  }  else {
    return count + " Bet";
  }
Why my code isn't working?
I think I've done everything according to the camp
Manish Giri
@Manish-Giri
Apr 24 2017 04:26
@Jonhnwhantcoding your conditions are probably reversed
if(count >= 0){
    return  count + " Hold";
  }  else {
    return count + " Bet";
  }
themrslewis
@themrslewis
Apr 24 2017 04:26
i am having a challenge with "Selecting from many options with Switch Statements"
i think the problem is with the expression in line 5
Khoa Le
@Zacele
Apr 24 2017 04:27

function rot13(str) { // LBH QVQ VG!
   var chr=  str.split("");
  var newChr=[];
  var newStr = " ";
  var index = 0;
   for (var i =0 ; i<chr.length;i++){
     if(chr[i] ===/([A-M])/g){
      index= chr[i].charCodeAt(i) + 13;
     }
     else if(chr[i] ===/([N-Z])/g){
       index= chr[i].charCodeAt(i) - 13;        
     } else {

     }
    newChr.push(index);
   }

  return newChr;
}


// Change the inputs below to test
rot13("SERR PBQR PNZC");
could anyone check on my code please
Devon Thomas
@UmbraLegacy
Apr 24 2017 04:28
@Zacele , working on it.
Khoa Le
@Zacele
Apr 24 2017 04:29
@UmbraLegacy thanks
CamperBot
@camperbot
Apr 24 2017 04:29
zacele sends brownie points to @umbralegacy :sparkles: :thumbsup: :sparkles:
:cookie: 285 | @umbralegacy |http://www.freecodecamp.com/umbralegacy
Khoa Le
@Zacele
Apr 24 2017 04:29
I think my regex is not legit
themrslewis
@themrslewis
Apr 24 2017 04:29

function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch (val === "") {
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);

Manish Giri
@Manish-Giri
Apr 24 2017 04:29
@themrslewis case '1':
remove the quotes here
that makes it a string
Victoria Zambrano
@vzambrano98
Apr 24 2017 04:29
I think i have an infinite loop, can anyone help me?
function smallestCommons(arr) {
  arr.sort(function (a,b){return b-a;});
 var betweens=[];
  for (var i=arr[0]-1; i>arr[1]; i--) {
    betweens.push(i);
}


function algo (arr){  
     var a = arr[0];    var b= arr[1];
     var multiArr=[]; var x=a;
betweens.every(function(item){
while (multiArr.length !== betweens.length){
multiArr=[];
    if ((a*x)%item===0 && (b*x)%item===0){
      multiArr.push(item);}
   if (multiArr.length===betweens.length){
     return a*x;
     } else { 
       x++;
       }

  }//.while
  });//.every
}//algo fxn
  return algo(arr);
}
smallestCommons([1,3]);
zacharydylan
@zacharydylan
Apr 24 2017 04:31
@Zacele You need .test()
Hold for link.
Victoria Zambrano
@vzambrano98
Apr 24 2017 04:31
well. I mean I wrote it that way. but it should terminate.
zacharydylan
@zacharydylan
Apr 24 2017 04:32
abdi rahman
@abdiezy
Apr 24 2017 04:34
i dont know why this doesn't work... any help?
function sumFibs(num) {

 var first = 0, second = 1, next;
   for(var i =0; i < num; i++){
     if ( i <= 1 )
         next = i;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }
     return next;
   }
}

sumFibs(4);
themrslewis
@themrslewis
Apr 24 2017 04:35
i remove the single ' ' quotes but it still doesn't compute
Bluestin
@Bluestin
Apr 24 2017 04:37
testing
testing2
~~testing 3~~
zacharydylan
@zacharydylan
Apr 24 2017 04:37
@abdiezy Your return statement is inside the loop, so will always return the first number in the loop.
Bluestin
@Bluestin
Apr 24 2017 04:38
~~testing3failed~~
'code'
abdi rahman
@abdiezy
Apr 24 2017 04:39
@zacharydylan something goes for outside loop... it return the last number in loop
Bluestin
@Bluestin
Apr 24 2017 04:39
`code`
zacharydylan
@zacharydylan
Apr 24 2017 04:40
@abdiezy I don't remember the end goal, I am assuming you are supposed to add all of the elements of fib up to that number?
abdi rahman
@abdiezy
Apr 24 2017 04:40
@zacharydylan not all just the odd ones....
zacharydylan
@zacharydylan
Apr 24 2017 04:43
@abdiezy Isn't that what you want?
I ran your code with the return outside the loop.
It returned 2.
Is there another test case it is failing?
abdi rahman
@abdiezy
Apr 24 2017 04:44
@zacharydylan try console.loging
Khoa Le
@Zacele
Apr 24 2017 04:46
@Bluestin i tested it all and it select the right character
zacharydylan
@zacharydylan
Apr 24 2017 04:46
@abdiezy Yeah, it's further on you are worried about. have you considered pushing your values to an array and using something like reduce to get your sum?
Bluestin
@Bluestin
Apr 24 2017 04:47
@Zacele I didn't understand you
Khoa Le
@Zacele
Apr 24 2017 04:49
the Caesars Cipher challenge
Victoria Zambrano
@vzambrano98
Apr 24 2017 04:50
so I'm stuck on smallest common multiples. i solved it but the for loops made it too long and now I have to make it work but streamline. which is killing me. can anyone help me?
function smallestCommons(arr) {
  arr.sort(function (a,b){return b-a;});
 var betweens=[];
  for (var i=arr[0]-1; i>arr[1]; i--) {
    betweens.push(i);
}
function algo (arr){  
     var a = arr[0];    var b= arr[1];
     var multiArr=[]; var x=a;
betweens.every(function(item){
while (multiArr.length !== betweens.length){
multiArr=[];
    if ((a*x)%item===0 && (b*x)%item===0){
      multiArr.push(item);}
   if (multiArr.length===betweens.length){
     return a*x;
     } else { 
       x++;
       }
  }//.while
  });
}
  return algo(arr);
}
smallestCommons([1,3]);
abdi rahman
@abdiezy
Apr 24 2017 04:52
@zacharydylan even console.loging is not accurate... there is one value missing... it supposed to be like 0, 1, 1, 2, 3, 5, 8, 13 and so on
Ming Zhu
@chocobrownie
Apr 24 2017 04:52

var colorR=200;
var colorG=100;
var colorB=100;
var colorArray=[];
var colorRGB="";
colorArray[0]="rgb("
colorArray[1]=toString(colorR);
colorArray[2]=",";
colorArray[3]=toString(colorG);
colorArray[4]=",";
colorArray[5]=toString(colorB);
colorArray[6]=")";
colorRGB=colorArray.join("");
 $(document).ready(function(){

    });
  $(".new-quote").click(function(){
    $(".main-color").animate({
  backgroundColor:colorRGB
    },500);
  });
I'm working on random quote machine and I want to have full control handle over my rgb color parameters. Below is my code in JavaScript section. It will work if I put a "rgb(200,100,100)" after "backgroundColor:", but by joining it to string, it doesn't work. Any idea what went wrong?
zacharydylan
@zacharydylan
Apr 24 2017 04:54
@abdiezy Add a variable and set it to an empty array. Then push next to that array each time through. return that array. You will see the sequence.
@Zacele You are also using the wrong index for .charCodeAt. You are testing a new individual string, so using i will return NaN as that index normally won't exist for the new string you are testing.
abdi rahman
@abdiezy
Apr 24 2017 04:56
@zacharydylan true thanks for the assist
CamperBot
@camperbot
Apr 24 2017 04:56
abdiezy sends brownie points to @zacharydylan :sparkles: :thumbsup: :sparkles:
:cookie: 309 | @zacharydylan |http://www.freecodecamp.com/zacharydylan
zacharydylan
@zacharydylan
Apr 24 2017 04:57
@abdiezy Are you able to use array methods to finish the challenge, or would you like some links for direction?
Ming Zhu
@chocobrownie
Apr 24 2017 04:59
@zacharydylan Could u help me on this?
Moisés Man
@moigithub
Apr 24 2017 05:00
colorR.toString()
or
String(colorR)
or
""+colorR
Manjula Konappanavar
@manjulam83
Apr 24 2017 05:01
Caesars Cipher
can any one tell me how to do this challenge
Edward
@lenvirthus
Apr 24 2017 05:01

// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[0][2];

why does myData = 3 ?

zacharydylan
@zacharydylan
Apr 24 2017 05:01
@chocobrownie Maybe, what is this?
Ming Zhu
@chocobrownie
Apr 24 2017 05:02
@zacharydylan Let me repost
var colorR=200;
var colorG=100;
var colorB=100;
var colorArray=[];
var colorRGB="";
colorArray[0]="rgb("
colorArray[1]=toString(colorR);
colorArray[2]=",";
colorArray[3]=toString(colorG);
colorArray[4]=",";
colorArray[5]=toString(colorB);
colorArray[6]=")";
colorRGB=colorArray.join("");
 $(document).ready(function(){

    });
  $(".new-quote").click(function(){
    $(".main-color").animate({
  backgroundColor:colorRGB
    },500);
  });
I'm working on random quote machine and I want to have full control handle over my rgb color parameters. Below is my code in JavaScript section. It will work if I put a "rgb(200,100,100)" after "backgroundColor:", but by joining it to string, it doesn't work. Any idea what went wrong? @zacharydylan
Moisés Man
@moigithub
Apr 24 2017 05:03
lemme repost @chocobrownie
colorR.toString()
or
String(colorR)
or
""+colorR
Ming Zhu
@chocobrownie
Apr 24 2017 05:03
@moigithub I'm so sorry I didn't see this
Let me try it
Moisés Man
@moigithub
Apr 24 2017 05:03
or u can just put the number in the array.. join will transform to string
zacharydylan
@zacharydylan
Apr 24 2017 05:04
Oh, sorry @moigithub didn't realize you were already trying.
Edward
@lenvirthus
Apr 24 2017 05:04

// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[0][2];

anyone know why myData array equals 11?

Ming Zhu
@chocobrownie
Apr 24 2017 05:07
@moigithub All your methods worked out, thank you very much
CamperBot
@camperbot
Apr 24 2017 05:07
chocobrownie sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3155 | @moigithub |http://www.freecodecamp.com/moigithub
Kuriakin Zeng
@kuriakinzeng
Apr 24 2017 05:20
@lenvirthus doesnt make sense. Maybe u wanna share the entire code
Aizaz Shahid
@aizazshahid
Apr 24 2017 05:22
why that is returning // 3
var array = [2, 3];
var max = Math.max.apply(null, array);
console.log(max);   // 3
Markus Kiili
@Masd925
Apr 24 2017 05:23
@forwebtech It is the maximum number on the array.
Aizaz Shahid
@aizazshahid
Apr 24 2017 05:24
@Masd925 oh , i was thinking that it adds the array :D
thanks @Masd925
CamperBot
@camperbot
Apr 24 2017 05:24
forwebtech sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 3911 | @masd925 |http://www.freecodecamp.com/masd925
Khoa Le
@Zacele
Apr 24 2017 05:27
@moigithub hey man
could you check my code to see what is wrong
Aizaz Shahid
@aizazshahid
Apr 24 2017 05:27
instead this works fine,
array.reduce((a, b) => a + b)
Khoa Le
@Zacele
Apr 24 2017 05:27

function rot13(str) { // LBH QVQ VG!
    var cipherText = "";
    for (var i = 0 ; i< str.length; i++){
      var cipherChar= cipherText.charCodeAt(i);
      if (cipherChar >=65 && cipherChar <= 77){
        cipherText += String.fromCharCode(cipherChar +13);
      } else if(cipherChar <=90 && cipherChar >= 78 ){
        cipherText += String.fromCharCode(cipherChar -13);
      }else {
        cipherText += String.fromCharCode(cipherChar);
    }
  return cipherText;
   }
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
/
Aizaz Shahid
@aizazshahid
Apr 24 2017 05:27
completely forgot it !
Khoa Le
@Zacele
Apr 24 2017 05:28

function rot13(str) { // LBH QVQ VG!
    var cipherText = " ";
    for (var i = 0 ; i< str.length; i++){
      var cipherChar= cipherText.charCodeAt(i);
      if (cipherChar >=65 && cipherChar <= 77){
        cipherText += String.fromCharCode(cipherChar +13);
      } else if(cipherChar <=90 && cipherChar >= 78 ){
        cipherText += String.fromCharCode(cipherChar -13);
      }else {
        cipherText += String.fromCharCode(cipherChar);
    }

   }
  return cipherText;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Ming Zhu
@chocobrownie
Apr 24 2017 05:28
Quick question: What's the difference between these two lines of codes? Is it necessary that we have the first one working and still need the second one?
$("getQuoteButton").on("click", function() {
targetOnCallFunction();
});

$("getQuoteButton").click(function() {
targetOnCallFunction();
});
Aizaz Shahid
@aizazshahid
Apr 24 2017 05:29
@chocobrownie first one is wrong because .on is not exist
it should be .onclick
Nathan Vu
@NathanVu
Apr 24 2017 05:30

// Declare your variable here
 var myGlobal = 10; 

function fun1() {
  // Assign 5 to oopsGlobal Here
 oopsGlobal = 5;
}

// Only change code above this line
function fun2() {
  var output = "";
  if (typeof myGlobal != "undefined") {
    output += "myGlobal: " + myGlobal;
  }
  if (typeof oopsGlobal != "undefined") {
    output += " oopsGlobal: " + oopsGlobal;
  }
  console.log(output);
}
Markus Kiili
@Masd925
Apr 24 2017 05:30
@Zacele Get the charcodes from str, not cipherText
Nathan Vu
@NathanVu
Apr 24 2017 05:30
guy why am I getting an undefine for this?
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 05:30
Hey guys, can someone tell me why this is wrong?

//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
  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";
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
zacharydylan
@zacharydylan
Apr 24 2017 05:30
@chocobrownie The first is a general event listener that you could use for other events, the second is specifically for the click event. If the first is working, the second is not necessary.
Nathan Vu
@NathanVu
Apr 24 2017 05:30
Can someone help me understand whats happening. I pass this. Just not getting the logic
Ming Zhu
@chocobrownie
Apr 24 2017 05:31
Markus Kiili
@Masd925
Apr 24 2017 05:31
@Rafewey Check the loop condition.
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 05:31
@Masd925 omg....
@Masd925 Wrong conditional...
Aizaz Shahid
@aizazshahid
Apr 24 2017 05:32
@chocobrownie ?? what's that
Markus Kiili
@Masd925
Apr 24 2017 05:32
@NathanVu oopsGlobal = 5; using the variable without var makes it a global variable.
Khoa Le
@Zacele
Apr 24 2017 05:32
@NathanVu what is your problem
Ming Zhu
@chocobrownie
Apr 24 2017 05:32
@zacharydylan Then why do they still come up with the second one? Isn't it necessary to have standard general syntax so everyone can stay on the same page? Plus it is not more complex than the second code
@forwebtech This is where I saw the "on" option code. And they say it works
Khoa Le
@Zacele
Apr 24 2017 05:32
@Masd925 thanks man, wow, such a stupid mistake
CamperBot
@camperbot
Apr 24 2017 05:32
zacele sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 3912 | @masd925 |http://www.freecodecamp.com/masd925
Nathan Vu
@NathanVu
Apr 24 2017 05:33
@Zacele when I run this code I'm getting an undefine
zacharydylan
@zacharydylan
Apr 24 2017 05:34
@chocobrownie They give you a simple method for clicks which are common and a more robust method that can be more adaptable to other situations.
Aizaz Shahid
@aizazshahid
Apr 24 2017 05:35
for posting long code please use http://gist.github.com/
Ming Zhu
@chocobrownie
Apr 24 2017 05:36
@forwebtech are you talking to me?
@zacharydylan Noted, I will remember what you said when I get there, thanks.
CamperBot
@camperbot
Apr 24 2017 05:36
chocobrownie sends brownie points to @zacharydylan :sparkles: :thumbsup: :sparkles:
:cookie: 310 | @zacharydylan |http://www.freecodecamp.com/zacharydylan
Aizaz Shahid
@aizazshahid
Apr 24 2017 05:36
to everybody !
Ming Zhu
@chocobrownie
Apr 24 2017 05:37
Ok I use, "```" it also works
Aizaz Shahid
@aizazshahid
Apr 24 2017 05:37
i checked it today and its really usefull, because your code is just at one place so also you can modify it !
Joseph
@revisualize
Apr 24 2017 05:38
Hello.
Aizaz Shahid
@aizazshahid
Apr 24 2017 05:39
@revisualize Welcome !
Markus Kiili
@Masd925
Apr 24 2017 05:39
@revisualize Yo.
LeSean Johnson
@leseanbiz
Apr 24 2017 05:39
whats the easiest way to test the weather app? just plugging in various zip values?
Aizaz Shahid
@aizazshahid
Apr 24 2017 05:39

@chocobrownie read it it's for .on

Description: Attach an event handler function for one or more events to the selected elements

LeSean Johnson
@leseanbiz
Apr 24 2017 05:39
i cant find anything about testing in their docs
Joseph
@revisualize
Apr 24 2017 05:40
@leseanbiz Depends how you code your web page.
LeSean Johnson
@leseanbiz
Apr 24 2017 05:40
i would hope they had dummy zips or something i could plug in to trigger one of their weather statuses
Aizaz Shahid
@aizazshahid
Apr 24 2017 05:40
its not just for click, .click is surely specific to click @chocobrownie
LeSean Johnson
@leseanbiz
Apr 24 2017 05:40
well, i havent gotten the geolocation part plugged in, just the background changing
and i see it is working mostly but i wish i could test in a more determinate way than just googling zip codes for different types of weather
jaganjaan
@jaganjaan
Apr 24 2017 05:41
how to get today date in this formate "Apr 13, 2017"
???
Joseph
@revisualize
Apr 24 2017 05:47
I've been watching videos about Docker this evening.
I need to get my ass to bed.
Gomathi Sankar
@Sankar88
Apr 24 2017 05:48
Stand in Line: queue
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
There is no example solution for this problem
Markus Kiili
@Masd925
Apr 24 2017 05:48
@jaganjaan The Date object has methods like https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString That method has some options for formatting the result. That is of some help at least.
Joseph
@revisualize
Apr 24 2017 05:48
@Sankar88 There isn't.

@Sankar88 Gist by revisualize / FreeCodeCamp - Stand in Line.js
You're supposed to:
Write a function nextInLine which has two parameters
an array (arr) and a number (item).
That part has been done for you here:

function nextInLine(arr, item) { }

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

You just need to add a number (item) to the end of an array (arr).
You also need to remove the first element from an array (arr) and you need to return the element that was removed.

So, How do you add a number (item) to the end of an array (arr)?
How do you remove the first element from an array (arr)?
...
Here's a brief example about how to use parameters:

function hello(fName, uName) {
     return "Hello " + fName + " " + uName + ", How is your day?";
}
hello("Joseph", "@revisualize"); // "Hello Joseph @revisualize, How is your day?"
hello("Bella", "@bellaknoti"); // "Hello Bella @bellaknoti, How is your day?"
hello("Andy", "@dirn"); // "Hello Andy @dirn, How is your day?"

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

jaganjaan
@jaganjaan
Apr 24 2017 05:49
@Masd925 thanks
CamperBot
@camperbot
Apr 24 2017 05:49
jaganjaan sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 3913 | @masd925 |http://www.freecodecamp.com/masd925
Gomathi Sankar
@Sankar88
Apr 24 2017 05:51
we can use push to add and shift function to remove first element and assign to variable
But its not working, when i tried it!
Joseph
@revisualize
Apr 24 2017 05:52
@Sankar88 Do you have code to show?
Aizaz Shahid
@aizazshahid
Apr 24 2017 05:53
@Sankar88 no it actually modify original array.
.push() & .shift()
Joseph
@revisualize
Apr 24 2017 05:53
@Sankar88 Because, on the surface. You gave the correct answer. However, you're not getting the correct response. So.. I need more information.
Gomathi Sankar
@Sankar88
Apr 24 2017 05:54
I got it, there might have been some typo
function nextInLine(arr, item) {
// Your code here
arr.push(item);
item = arr.shift();
return item; // Change this line
}
Thanks for the suggestion!
Joseph
@revisualize
Apr 24 2017 05:54
@Sankar88 That works. You don't need to overwrite the item variable.
@Sankar88 You can just return the .shift()
Gomathi Sankar
@Sankar88
Apr 24 2017 05:54
return arr.shift()
Joseph
@revisualize
Apr 24 2017 05:55
Saves overwriting a variable and minimizes code issues.
@Sankar88 Yes.
Gomathi Sankar
@Sankar88
Apr 24 2017 05:55
ok, Thanks!
Markus Kiili
@Masd925
Apr 24 2017 05:55
@Sankar88 If you wan't to use a variable for storing the removed element, it is better to make a new variable. Avoids confusion.
You can use such variables at start for clarity, but better to learn to remove them later.
Joseph
@revisualize
Apr 24 2017 05:56
Yeah, you may need to use the parameter over again.
Depends on your code objective.
meh
Markus Kiili
@Masd925
Apr 24 2017 05:56
Also harder to read when the meaning of the variable changes.
LeSean Johnson
@leseanbiz
Apr 24 2017 06:00
why would passing the openweathermap api a zipcode that shows as snowy/icy on bother weather.com & wunderground.com error out when it works fine for my person zip? anyone else bail and use a different api for this project?
kirbyedy
@kirbyedy
Apr 24 2017 06:01
@leseanbiz yes, darksky
LeSean Johnson
@leseanbiz
Apr 24 2017 06:03
ahh, might have to do that. but ive already written this to work off of the weather id from openweathermap. thanks! @kirbyedy
CamperBot
@camperbot
Apr 24 2017 06:03
leseanbiz sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:star2: 2034 | @kirbyedy |http://www.freecodecamp.com/kirbyedy
Roman
@RPG007
Apr 24 2017 06:22
Can someone pls help with "Convert Celsius to Fahrenheit" I have no clue on what to do
devpaaji
@devpaaji
Apr 24 2017 06:25
```
function foo(a, b) {
    arguments[1] = 2;
    alert(b); // undefined, I worked out to be 2
}
foo(1);
@Masd925
Aizaz Shahid
@aizazshahid
Apr 24 2017 06:26
@RPG007 yes !
@RPG007 you have to use that formula which is already mentioned in the instructions !
may be !
a27-suryansh
@a27-suryansh
Apr 24 2017 06:28
Can someone explain me the exact difference between substring and substr in JS with some example ?
Aizaz Shahid
@aizazshahid
Apr 24 2017 06:29
@a27-suryansh substr && subString
a27-suryansh
@a27-suryansh
Apr 24 2017 06:30
Yes i read that both functions seems to do same thing
@forwebtech
Suppose i have a string " Orange cyan"
if i use substring(0,3); it will return Ora right?
Aizaz Shahid
@aizazshahid
Apr 24 2017 06:32
right !
a27-suryansh
@a27-suryansh
Apr 24 2017 06:32
and substr returns the same?
Aizaz Shahid
@aizazshahid
Apr 24 2017 06:33
wait just giving you example !
Aizaz Shahid
@aizazshahid
Apr 24 2017 06:38
@a27-suryansh The difference is in the second argument. The second argument to substring is the index to stop at (but not include), but the second argument to substr is the maximum length to return
a27-suryansh
@a27-suryansh
Apr 24 2017 06:39
Thanks @forwebtech got it
CamperBot
@camperbot
Apr 24 2017 06:39
a27-suryansh sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 323 | @forwebtech |http://www.freecodecamp.com/forwebtech
devpaaji
@devpaaji
Apr 24 2017 06:39
why it is giving undefined @Masd925
Baderfahad
@Baderfahad
Apr 24 2017 06:43
hey guys :D
Roman
@RPG007
Apr 24 2017 06:43
suh dude
Baderfahad
@Baderfahad
Apr 24 2017 06:43
I want to ask . how I can put the codes here if I got stuck on somthing!
@RPG007 :D
Roman
@RPG007
Apr 24 2017 06:44
Take a screenshot
Gyazo maybe
Baderfahad
@Baderfahad
Apr 24 2017 06:45
how to take a screenshot haha !
?
Roman
@RPG007
Apr 24 2017 06:45
you can either download gyazo for desktop or get the extension on the app store
it will give you a link to the screensho
Aizaz Shahid
@aizazshahid
Apr 24 2017 06:45
@a27-suryansh please look at this working example:
console.log("Computer".substr(1, 3));        // omp
console.log("Computer".substring(1, 3));    // om
Roman
@RPG007
Apr 24 2017 06:45
t
Baderfahad
@Baderfahad
Apr 24 2017 06:46
@RPG007 oh I see thank you :+1: !
CamperBot
@camperbot
Apr 24 2017 06:46
baderfahad sends brownie points to @rpg007 :sparkles: :thumbsup: :sparkles:
:cookie: 28 | @rpg007 |http://www.freecodecamp.com/rpg007
Aizaz Shahid
@aizazshahid
Apr 24 2017 06:46
@Baderfahad press print screen
Baderfahad
@Baderfahad
Apr 24 2017 06:46
@forwebtech oh ok thank you to you too :+1:
CamperBot
@camperbot
Apr 24 2017 06:46
baderfahad sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 324 | @forwebtech |http://www.freecodecamp.com/forwebtech
Aizaz Shahid
@aizazshahid
Apr 24 2017 06:46
then copy to mspaint and crop it and copy and just paste here !
Baderfahad
@Baderfahad
Apr 24 2017 06:46
ahh I see :+1:
Aizaz Shahid
@aizazshahid
Apr 24 2017 06:47
like this:
image.png
a27-suryansh
@a27-suryansh
Apr 24 2017 06:48
@forwebtech 0 = C right?
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 06:49
if you have windows you can just use the the windows snipping tool
Rin
@beaRINmind
Apr 24 2017 06:49
hi there! just wondering if i could grab some help. " Set remainder equal to the remainder of 11 divided by 3 using the remainder (%) operator." and this is my code
Aizaz Shahid
@aizazshahid
Apr 24 2017 06:49
@a27-suryansh yes the problem is that when you start from zero it will become same for both !
Rin
@beaRINmind
Apr 24 2017 06:49

// Only change code below this line

var remainder; 11 % 3 = 2;
a27-suryansh
@a27-suryansh
Apr 24 2017 06:49
ok @forwebtech
Roman
@RPG007
Apr 24 2017 06:49
get rid of the first semicolon
Aizaz Shahid
@aizazshahid
Apr 24 2017 06:50
@HeebieGeeBee yes, thanks, forgot about that @Baderfahad :point_up: April 24, 2017 11:49 AM
CamperBot
@camperbot
Apr 24 2017 06:50
forwebtech sends brownie points to @heebiegeebee and @baderfahad :sparkles: :thumbsup: :sparkles:
:cookie: 201 | @baderfahad |http://www.freecodecamp.com/baderfahad
:star2: 1438 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Roman
@RPG007
Apr 24 2017 06:50
@beaRINmind
Long Nguyen
@longnt80
Apr 24 2017 06:50
@Baderfahad
just paste your code between the backticks like this
alt
Rin
@beaRINmind
Apr 24 2017 06:50
@RPG007 i did, however it still doesnt work
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 06:51
@beaRINmind you just have to assign the formula to the variable
Roman
@RPG007
Apr 24 2017 06:51
hmm
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 06:51
you dont need to work out the calculation
Rin
@beaRINmind
Apr 24 2017 06:52
@HeebieGeeBee oh thanks a lot man i got it
CamperBot
@camperbot
Apr 24 2017 06:52
bearinmind sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1439 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Rin
@beaRINmind
Apr 24 2017 06:52
@RPG007 thanks a lot too!!
Roman
@RPG007
Apr 24 2017 06:52
Np man @beaRINmind :)
Roman
@RPG007
Apr 24 2017 06:58

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

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

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

Anyone know why its not working?
anderson
@anderson2825
Apr 24 2017 06:58
blob
why is wrong??
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 06:58
Hey guys what is the digit selector in this? I don't really understand how to use it.
// Setup
var testString = "There are 3 cats but 4 dogs.";

// Only change code below this line.

var expression = /.+/g;  // Change this line

// Only change code above this line

// This code counts the matches of expression in testString
var digitCount = testString.match(expression).length;
anderson
@anderson2825
Apr 24 2017 06:58
please help me
how can i solve this problem;
Roman
@RPG007
Apr 24 2017 07:00
```
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:00
@RPG007 youre meant to assign the formula to convert celsius to the fahrenheit thats provided in the structions to the fahrenheit variable
Roman
@RPG007
Apr 24 2017 07:01
um
a27-suryansh
@a27-suryansh
Apr 24 2017 07:02

Why my code is not working


function confirmEnding(str, target) {
var a = str.split(" ");
  var z=a.length-1;
  var b = a[z];
  var special = str.length-target.length;
  var c = b.substring(0,special);

  if (c=== target) {

    return true;
  }

  return false;
}


confirmEnding("Bastian", "n");

it is working for this confirmEnding("Open sesame", "same");

HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:02
@anderson2825 you shouldnt push the maxnew variable inside the if statement you should wait until youve looped through all the elements in the subarray
a27-suryansh
@a27-suryansh
Apr 24 2017 07:02
@HeebieGeeBee please help for this

Why my code is not working
```

function confirmEnding(str, target) {
var a = str.split(" ");
var z=a.length-1;
var b = a[z];
var special = str.length-target.length;
var c = b.substring(0,special);

if (c=== target) {

return true;

}

return false;
}

confirmEnding("Bastian", "n");

it is working for this ``` confirmEnding("Open sesame", "same");
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:03
@a27-suryansh special should just be target.length in negative
a27-suryansh
@a27-suryansh
Apr 24 2017 07:03
@HeebieGeeBee why?
like how?
anderson
@anderson2825
Apr 24 2017 07:04
okay! thanks! @HeebieGeeBee
CamperBot
@camperbot
Apr 24 2017 07:04
anderson2825 sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1440 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:04
and you just want to make a slice from the str thats -target.length
and campar it with target
making it a negative value will slice it from the end of the string
Deep Verma
@deepverma3003
Apr 24 2017 07:05
@anderson2825 the condition maxnew<newarr2[j] fails for the 4 array
a27-suryansh
@a27-suryansh
Apr 24 2017 07:05
@HeebieGeeBee can you write the code?
var special = ?
anderson
@anderson2825
Apr 24 2017 07:06
thanks ! @deepverma3003 I have solved this problem!
CamperBot
@camperbot
Apr 24 2017 07:06
anderson2825 sends brownie points to @deepverma3003 :sparkles: :thumbsup: :sparkles:
:cookie: 311 | @deepverma3003 |http://www.freecodecamp.com/deepverma3003
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 07:06
Can someone tell me why this isnt working?
tundeiness
@tundeiness
Apr 24 2017 07:06
hi all I have a challenge with this task. my idea is that I should run a for loop which will equal the number of row(size) and likewise the inner loop too. But i'm guessing after slicing or splicing, i'm not storing the spliced element correctly so I think I need a heads up on that. However should there be any other things noticed please indicate... so the code goes below:
function chunkArrayInGroups(arr, size) {

  var arrSize = arr.length;


    var origArr = arr;



    for(var i = 0; i < size; ++i){

        var storeArr = [];


       for( var j = 0; j < size; ++j){

        storeArr.push(origArr.splice(0, size));


       }

        return storeArr;

    } 


}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 07:06
// Setup
var testString = "There are 3 cats but 4 dogs.";

// Only change code below this line.

var expression = /\3+4/g;  // Change this line

// Only change code above this line

// This code counts the matches of expression in testString
var digitCount = testString.match(expression).length;
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:06
special = -target.length
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 07:06
Why isnt this working?
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:06
@a27-suryansh
a27-suryansh
@a27-suryansh
Apr 24 2017 07:07
@HeebieGeeBee it is not accepting - after =
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:07
@Rafewey what are you trying to do?
@a27-suryansh whats your code look like?
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 07:08
@HeebieGeeBee I am trying to select "3" and "4" from trstString
devpaaji
@devpaaji
Apr 24 2017 07:08
@HeebieGeeBee hey hello mate
how are you
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:08
@devpaaji yo, im alright
a27-suryansh
@a27-suryansh
Apr 24 2017 07:08
@HeebieGeeBee

function confirmEnding(str, target) {
var a = str.split(" ");
  var z=a.length-1;
  var b = a[z];
  var special = str.length-target.length;
  var c = b.substring(0,special);

  if (c=== target) {

    return true;
  }

  return false;
}


confirmEnding("Open sesame", "same");
Aizaz Shahid
@aizazshahid
Apr 24 2017 07:08

@HeebieGeeBee
https://gist.github.com/forwebtech/cb91056ce999953f2566b3c9ca16d4ef

in that, all is working fine but it should to return undefined when string is pass, but it just printing the closure method name, addTogether("abcd");`

HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:08
@Rafewey use /\d/g
@devpaaji hows you?
Mathew Gellner-Garcia
@Rafewey
Apr 24 2017 07:09
@HeebieGeeBee Doesnt work.
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:10
@a27-suryansh i dont see where youre using it
Aizaz Shahid
@aizazshahid
Apr 24 2017 07:10
@a27-suryansh still stuck ???
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:10
@Rafewey match just returns true or false
tundeiness
@tundeiness
Apr 24 2017 07:11
any help please?
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:11
@HeebieGeeBee oops sorry thats test
@Rafewey
got them confused
Galib Hossain
@formulajp60
Apr 24 2017 07:13
Hello, guys.
Is there any way to remove empty arrays from two dimensional arrays?
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:13
@Rafewey
// Setup
var testString = "There are 3 cats but 4 dogs.";

// Only change code below this line.

var expression = /\d/g;  // Change this line

// Only change code above this line

// This code counts the matches of expression in testString
var digitCount = testString.match(expression).length;

console.log(digitCount); // this returns 2
Galib Hossain
@formulajp60
Apr 24 2017 07:13
I am getting this result;
[[0,1,2,3] , [4,5], [ ], [ ] ]
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:16
@formulajp60 slice them out
Galib Hossain
@formulajp60
Apr 24 2017 07:16
slice or splice?
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:16
splice sorry
or use the reduce method
Galib Hossain
@formulajp60
Apr 24 2017 07:18
I am pushing arrays to another array through a loop.
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:19
@tundeiness first declare that storeArr outide the loop and make the return outside the loop too
Galib Hossain
@formulajp60
Apr 24 2017 07:19
the problem is the loop pushes empty arrays after populating the other array
function chunkArrayInGroups(arr, size) {
  // Break it up.
  var twoD = [];
  var n = 0; 
  var s = size;

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

    twoD.push( arr.slice(n, s) );

    n += size;
    s += size;
  }

  return twoD.splice(0, size);

}

chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4)
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:20
@tundeiness and if youre using splice maybe a while loop would be better
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:20
hey guys
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:20
@formulajp60 use i+=size for your loop iteration
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:20
ive been working on this one for days.
Title Case a Sentence
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:21
and then just use your i variable for your slice arguments
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:21

function titleCase(str) {
  var lower = str.toLowerCase();
  var firstLetter;
  var splitup = lower.split(' ');
  for (var i=0; i< splitup.length; i++){
  firstLetter = splitup[i][0].toUpperCase();}

  var newArray;
  for (var x=0; x< splitup.length; x++){
  newArray[x] += firstLetter[x];}
  return newArray.join(" ");
}

titleCase("I'm a little tea pot");
I know i'm doing things wrong here. Do I just scrap my code at this point?
Deep Verma
@deepverma3003
Apr 24 2017 07:21
@newbcoder91 No
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:22
@newbcoder91 strings are immutable
Deep Verma
@deepverma3003
Apr 24 2017 07:22
Just need to modify a bit
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:22
Right, I know they are
Long Nguyen
@longnt80
Apr 24 2017 07:22
@a27-suryansh
you should not try to split the str
var a = str.split(" ");
Deep Verma
@deepverma3003
Apr 24 2017 07:22
@newbcoder91 You need to store them in array
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:22
@newbcoder91 you could do it all with one loop
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:22
@deepverma3003 didn't i do that?
Deep Verma
@deepverma3003
Apr 24 2017 07:23
and use .toUpperCase
the first word
Wait
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:23
after you split the array into words just replace every elements with the element thats the words first character in uppercase with the rest of the word concatted
@newbcoder91
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:23
do i use the replace() then?
like replace().toUpperCase?
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:24
well you dont have to use replace
NaveenRathor
@NaveenRathor
Apr 24 2017 07:24
what's wrong in my code?

var a = function reverseString(str) {
return str.reverse();
};

reverseString("hello");

HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:25
splitup[i] = spiltup[i][0].toUpperCase() + ...... @newbcoder91
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:25
ah
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:25
@NaveenRathor reverse is an array method
you need to split a string into an array first
NaveenRathor
@NaveenRathor
Apr 24 2017 07:26
@HeebieGeeBee ok
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:26
why is my name in red?
nevermind.
Abdallah Sarhan
@AbdallahSarhan
Apr 24 2017 07:27
what's wrong with this code?

function palindrome(str) {
  var patt = str.slice(0).match(/[a-z,0-9]/ig);
  var ex = patt.join().toLowerCase().split(",");
  var revex = ex.slice(0).reverse().toString();
  var exAfter = ex.slice(0).join(",");
  if (exAfter === revex){
    return true;
  }
  else {
    return false;
  }
}
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:27
@HeebieGeeBee that only returns the first letter of each string
so it gives me I A L T P
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:27
@newbcoder91 the .... meant you had to do something more too
tundeiness
@tundeiness
Apr 24 2017 07:28
@HeebieGeeBee okay
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:28
i didnt want to give you all the code
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:28
makes sense. can i add slice?
Abdallah Sarhan
@AbdallahSarhan
Apr 24 2017 07:28
when i do return revex & exAfter >>> they look the same in Console
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:28
with the loop?
like slice[i]
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:28
@newbcoder91 thers no need for aloop
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:29
i mean with in my current loop
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:29
str.slice(1) will take a slice of a string without the first letter
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:29
But I need to do that for each word
So I need a loop
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:30
@AbdallahSarhan i dont know why youre using join as the first method in ex and i dont know why youre using slice in revex and exafter
tundeiness
@tundeiness
Apr 24 2017 07:31
@HeebieGeeBee still stuck
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:31
@newbcoder91 but youre already doing a loop you just need to adda slice to the expression
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:31
right, thats what i thought
Long Nguyen
@longnt80
Apr 24 2017 07:31
:point_up: April 24, 2017 2:08 PM
Still need help? @a27-suryansh
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:32
so if slice(1) takes all but the first letter, can i use an index with my slice?
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:32
@newbcoder91 you dont need to
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:32
Im not sure I follow
tundeiness
@tundeiness
Apr 24 2017 07:32
@HeebieGeeBee will use slice instead... I keep getting [a , b], [a, b] ...meaning it was not successful in getting to slice [c , d]
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:32
just splitup[i].slice(1)
@newbcoder91
@tundeiness show your code
Nehemiah Kivelevitz
@NehemiahK
Apr 24 2017 07:33
ah
@HeebieGeeBee i cant use splitup[i].slice(1) on the lefthand side
Abdallah Sarhan
@AbdallahSarhan
Apr 24 2017 07:34
@HeebieGeeBee methods like reverse() will be applied to ex when i assigned it to revex >>> i mean this syntax >> revex = ex.reverse() >> ex will be affected , this is why
tundeiness
@tundeiness
Apr 24 2017 07:34
@HeebieGeeBee not using while though...i'll stick to the for loop but here is the code
function chunkArrayInGroups(arr, size) {

  var arrSize = arr.length;


    var origArr = arr;

    var storeArr = [];

    for(var i = 0; i < size; ++i){




       for( var j = 0; j < size; ++j){

        storeArr.push(origArr.slice(0, size));


       }



    } 

  return storeArr;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:34
@tundeiness why are you doing a nested loop?
@tundeiness and you should be using arr.length for the loop
@newbcoder91 what do you mean left hand side?
@newbcoder91 the slice should be added to the first letter in uppercase
tundeiness
@tundeiness
Apr 24 2017 07:35
@HeebieGeeBee my idea was to treat it like a matrix of some sort....that is a 2 x 2 matrix depending on the size?
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:36
@tundeiness no you just need to take slices and push them into a holding array
so you arr.length for the loop and then i+=size for your final expression so i increase by i each time
then you can use your i variable in your arguments for the slice
tundeiness
@tundeiness
Apr 24 2017 07:39
@HeebieGeeBee okay, let me try that out. but what about the storage line ? i'm thinking each time i slice, it should go into the storeArr depending on the size?
a27-suryansh
@a27-suryansh
Apr 24 2017 07:39
@longnt80 no thanks @forwebtech is helping me
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:39
@tundeiness just push the slices into the holding array, your loop variable should determine the size of the slice
Baderfahad
@Baderfahad
Apr 24 2017 07:39
I am just stucked a little bit in counting card thing
tundeiness
@tundeiness
Apr 24 2017 07:40
@HeebieGeeBee okay.
CraZy biRd
@Preeetrockz
Apr 24 2017 07:40
hello :)
Baderfahad
@Baderfahad
Apr 24 2017 07:40
my codes are right but why the #did not have any check ?
HeebieGeeBee
@HeebieGeeBee
Apr 24 2017 07:40
@Preeetrockz hi
Baderfahad
@Baderfahad
Apr 24 2017 07:41
#4 did not have any check
Abdallah Sarhan
@AbdallahSarhan
Apr 24 2017 07:41
@HeebieGeeBee methods like reverse() will be applied to ex when i assigned it to revex >>> i mean this syntax >> revex = ex.reverse() >> ex will be affected , this is why i use slice (0),
and join() with ex because match() returns a list and i want to lowercase so i turn it to string
ioakeimo
@ioakeimo