15th
Jun 2017
NielEXXCRO
@EkweviIkeobi
Jun 15 2017 00:00
@JLuboff lol i uessed as much
Lance Ward
@Lanceward410
Jun 15 2017 00:00
@pursuitgit Establish a numeric variable "longestWord" outside of your for loop equal to 0. If wordsArray[i] is greater than this value, set the new longestWord equal to that word's length
pursuitgit
@pursuitgit
Jun 15 2017 00:00
@Lanceward410 I think i've got it!

function findLongestWord(str) {

var length = 0;

wordsArray = str.split(" ");

for (var i = 0; i < wordsArray.length; i++)
{
if (wordsArray[i].length > length)
{
length = wordsArray[i].length;
str = wordsArray[i];
}
}
return str.length;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
@Lanceward410 thanks for the help, I shamefully had to look at stackoverflow for some assistance, is that bad practice?
CamperBot
@camperbot
Jun 15 2017 00:01
pursuitgit sends brownie points to @lanceward410 :sparkles: :thumbsup: :sparkles:
Lance Ward
@Lanceward410
Jun 15 2017 00:02
@pursuitgit Sweet! I check external resources all the time. As long as you use the information properly and learn from it, it's not bad
@pursuitgit Now you can be stuck on the next one with me...
pursuitgit
@pursuitgit
Jun 15 2017 00:02
@Lanceward410 haha lets do it! It's 10am here in Aus everyone else will come into the office soon so I might have to stop coding though
angus
@dangus21
Jun 15 2017 00:03

@pursuitgit
function findLongestWord(str) {

var Lstr = str.split(" ");
var final = Lstr.sort(function (a, b) { return b.length - a.length; })[0];
return final.length;
}

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

done (:
pursuitgit
@pursuitgit
Jun 15 2017 00:05
@Lanceward410 maybe with the next one we create multi dimensional arrays, an array of each word then each word is an array
@Lanceward410 then we just capitalise the first element in each word array with .touppercase()
@Lanceward410 what do you think?
@dangus21 thanks dangus, just figured it out before your answer but you provided a way cleaner way of doing it. It looks pretty intense though I don't think I could of thought of that.
CamperBot
@camperbot
Jun 15 2017 00:06
pursuitgit sends brownie points to @dangus21 :sparkles: :thumbsup: :sparkles:
Ryan Nelson
@iamryandnelson
Jun 15 2017 00:07
I want to call a function once the animation is complete (once my timescale image stops animating). I've tried this (myDraggable.eventCallback("onComplete", complete);) in a few different variations, but it's not working. What am I doing wrong?
https://codepen.io/iamryandnelson/pen/dRbKMM?editors=0010
angus
@dangus21
Jun 15 2017 00:07
well, you remove the spaces and turn the old array into a new one, sort it and get the first element of the sorted array and check its length (:
Greg Duncan
@GregatGit
Jun 15 2017 00:10
@iamryandnelson looks great - very unclear how to make it start
@iamryandnelson myDraggable.eventCallback is not a function
monkeyfingerz
@monkeyfingerz
Jun 15 2017 00:12
function largestOfFour(arr) {
// You can do this!
var array=[];
var largest=[];
for (var i =0;i<arr.length;i++){
for(var j=0;j<arr.length;j++){

array.push(arr[i][j]);

}

}

}

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

function largestOfFour(arr) {
// You can do this!
var array=[];
var largest=[];
for (var i =0;i<arr.length;i++){
for(var j=0;j<arr.length;j++){

array.push(arr[i][j]);

}

}

}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
angus
@dangus21
Jun 15 2017 00:13
what even...
Ryan Nelson
@iamryandnelson
Jun 15 2017 00:13
@GregatGit "myDraggable.eventCallback is not a function". I'm not sure what that means. Do you see how I can write it correctly?
monkeyfingerz
@monkeyfingerz
Jun 15 2017 00:14
sorry
Keon Samuel
@keonsam
Jun 15 2017 00:15
eventCallback is not a function
Greg Duncan
@GregatGit
Jun 15 2017 00:15
@iamryandnelson line 41 myDraggable.eventCallback("onComplete", complete); you call eventCallback on the myDragable
Ryan Nelson
@iamryandnelson
Jun 15 2017 00:15
@GregatGit This where I'm getting this from: https://greensock.com/docs/#/HTML5/GSAP/TweenLite/eventCallback/
Keon Samuel
@keonsam
Jun 15 2017 00:15
some error somewhere.
Ryan Nelson
@iamryandnelson
Jun 15 2017 00:15
@GregatGit I must be reading it wrong, but not sure how...
angus
@dangus21
Jun 15 2017 00:16
there is nothing about it on mozilla... i call it fishy...
Keon Samuel
@keonsam
Jun 15 2017 00:17
is eventCallback a keyword?
I've never heard of it.
angus
@dangus21
Jun 15 2017 00:18
same
Ryan Nelson
@iamryandnelson
Jun 15 2017 00:18
@GregatGit Wait! I got it :). Check it out now.
Keon Samuel
@keonsam
Jun 15 2017 00:20
is that a framework or something?
Greg Duncan
@GregatGit
Jun 15 2017 00:21
@iamryandnelson nice
Ryan Nelson
@iamryandnelson
Jun 15 2017 00:22
@keonsam I think you're talking to me? Yes, it's called TweenLite and Draggable from Greensock. I saw that Codepen just added it as a default library option. It's pretty neat ;)
pursuitgit
@pursuitgit
Jun 15 2017 00:22
Hi guys can someone help me with title case to a sentence? I'm nearly done but I can't figure out how to make one of the tests pass

function titleCase(str) {
return str.toLowerCase().replace( /\b./g, function(a) { return a.toUpperCase();});
}

titleCase("I'm a little tea pot");
Ryan Nelson
@iamryandnelson
Jun 15 2017 00:22
@GregatGit Thanks, and thanks for responding. I really appreciate it.
CamperBot
@camperbot
Jun 15 2017 00:22
iamryandnelson sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
Delu
@Daniocerebral
Jun 15 2017 00:22
https://www.freecodecamp.com/challenges/local-scope-and-functions
I'm stuck at this challenge :( i know it's super simple can someone help me see what i'm doing whrong?
wrong*
pursuitgit
@pursuitgit
Jun 15 2017 00:23
this returns: I'M A Little Tea Pot
Jonathan
@jrhayes
Jun 15 2017 00:23

function rot13(str) { // LBH QVQ VG!
var ascii = [];
var cipher = [];
var decoded = [];

//iterate cipher
for (var i = 0; i < str.length; i++)
{
ascii = str.charCodeAt(i);
//convert A-Z to ROT13
if (ascii >=65 && ascii <= 90)
{
cipher.push(((ascii - 65) + 13) % 26);
}
//ignore non-(A-Z)
else
{
cipher.push(ascii);
}

}
//recovert to ascii A-Z
for (var j = 0; j < cipher.length; j++)
{
if (cipher[j] >= 0 && cipher[j] <= 25)
{
decoded.push(cipher[j] + 65);
}
else
{
decoded.push(cipher[j]);
}
}

//Not sure how to use .fromCharCode
console.log(String.fromCharCode(decoded));

return String.fromCharCode(decoded);

}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Can anyone help me here? I may be way over complicating this from where I've written this before in C. I'm not sure how to use the .fromCharCode()
angus
@dangus21
Jun 15 2017 00:23
Greg Duncan
@GregatGit
Jun 15 2017 00:23
@iamryandnelson its a great looking pen - I recommend moving the car instead of the scale below
Delu
@Daniocerebral
Jun 15 2017 00:24
someone? it's a really simple challenge
there must be something i'm missing
Ryan Nelson
@iamryandnelson
Jun 15 2017 00:24
@GregatGit I tried that, but the design didn't work for mobile :/.
Delu
@Daniocerebral
Jun 15 2017 00:26
Jonathan
@jrhayes
Jun 15 2017 00:26
@Daniocerebral read the last comment in the code
angus
@dangus21
Jun 15 2017 00:26
@delu i'm on it
pursuitgit
@pursuitgit
Jun 15 2017 00:27
My function passes every test except for returning "I'M A Little Tea Pot". can anyone help me figure this out please?

function titleCase(str) {
return str.toLowerCase().replace( /\b./g, function(a) { return a.toUpperCase();});
}

titleCase("I'm a little tea pot");
angus
@dangus21
Jun 15 2017 00:28
Delu
@Daniocerebral
Jun 15 2017 00:28
oh i totally missenterpreted that, thanks i got it now
angus
@dangus21
Jun 15 2017 00:29

@Daniocerebral
function myLocalScope() {
'use strict';
var myVar = "woo"

console.log(myVar);
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope

// Now remove the console log line to pass the test

Keon Samuel
@keonsam
Jun 15 2017 00:30
Alex
@alexandrupintilei
Jun 15 2017 00:32

function truncateString(str, num) {
// Clear out that junk in your trunk
var dots = "...";
var res = string.concat(dots);

if(num.length > 3){
return res.splice(num);

} else {

return res;
}

}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
what wrong?
angus
@dangus21
Jun 15 2017 00:33
Alex
@alexandrupintilei
Jun 15 2017 00:33
return string,also dont work
Will Hart
@willhart108
Jun 15 2017 00:34
stuck on the task 'convert celsius to Fahrenheit'. whats the line of code? prob not difficult but it's confusing me..
angus
@dangus21
Jun 15 2017 00:35
well, you are passing celcius are returning fahrenheit
mackyking
@mackyking
Jun 15 2017 00:36
Need some help guys...
Will Hart
@willhart108
Jun 15 2017 00:36
doesn't give an example of the line of code. is it right under my nose?
only a month into coding
mackyking
@mackyking
Jun 15 2017 00:37
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.
angus
@dangus21
Jun 15 2017 00:37
@mackyking whats up?
Alex
@alexandrupintilei
Jun 15 2017 00:37
mackyking
@mackyking
Jun 15 2017 00:38

function nextInLine(arr, item) {

return item; // Change this line
}

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

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

Greg Duncan
@GregatGit
Jun 15 2017 00:38
@alexandrupintilei you should be using the input param str not var string = "A-tisket a-t...
angus
@dangus21
Jun 15 2017 00:38
of the excercise
mackyking
@mackyking
Jun 15 2017 00:38
Alex
@alexandrupintilei
Jun 15 2017 00:39
@GregatGit i created the var string,so i can concate the two strings
i changed the code,and stil dosent work
JD Richards
@jdrichardstech
Jun 15 2017 00:40
@willhart108 so you are given the celsius in the argument. make fahrenheit equl to the celsius times (9 divided by 5) which they tell you and then add 32.
Alex
@alexandrupintilei
Jun 15 2017 00:40
i dont want the solution,just a hint
VinayVijayJoshi
@VinayVijayJoshi
Jun 15 2017 00:40
flasy bouncer challenge. My code below. What is wrong
function bouncer(arr) {
// Don't show a false ID to this bouncer.
var longWords = arr.filter(function(word){
return ((word !== false) && (word !== null) && (word !== 0) && (word !== "") && (word !== undefined) && (isNaN(word) !== true));
});
return longWords;
}

bouncer(["a", "b", "c"]);
Greg Duncan
@GregatGit
Jun 15 2017 00:40
@alexandrupintilei var res = str + '...'
Alex
@alexandrupintilei
Jun 15 2017 00:41
@GregatGit

mackyking
@mackyking
Jun 15 2017 00:41
Alex
@alexandrupintilei
Jun 15 2017 00:41

function truncateString(str, num) {
// Clear out that junk in your trunk
var res = str + "...";

if(num.length > 3){
return res.splice(num);

} else {

return string;
}

}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
dont work
mackyking
@mackyking
Jun 15 2017 00:42
pursuitgit
@pursuitgit
Jun 15 2017 00:42
@Lanceward410 how'd you go with 'Title Case a Sentence' I figured out the concept pretty quick but it took like 40 minutes to write it =.=
mackyking
@mackyking
Jun 15 2017 00:42
Can anybody will help me?
Greg Duncan
@GregatGit
Jun 15 2017 00:42
@alexandrupintilei I know - but at least you are failing using the param str - not creating your own
Alex
@alexandrupintilei
Jun 15 2017 00:43
@GregatGit even with my solution(which was not a good one),i obtain same result
Lance Ward
@Lanceward410
Jun 15 2017 00:43
@pursuitgit I am using a for loop again. Once I figure out how to put my thoughts into the right syntax....I'll be there
mackyking
@mackyking
Jun 15 2017 00:43
Greg Duncan
@GregatGit
Jun 15 2017 00:43
@alexandrupintilei try can get it to work on the first test to return 'A-tisket...'
pursuitgit
@pursuitgit
Jun 15 2017 00:44
@Lanceward410 I just got it done if you need some help! If you want some guidance with the logic let me know
Greg Duncan
@GregatGit
Jun 15 2017 00:44
@alexandrupintilei and there is no string anymore return string;
Alex
@alexandrupintilei
Jun 15 2017 00:44
@GregatGit i saw that
@GregatGit but stil dont work
Lance Ward
@Lanceward410
Jun 15 2017 00:45
@pursuitgit For loop, toUpperCase at charAt(0) for each element in my array (after splitting the original string into words)
Alex
@alexandrupintilei
Jun 15 2017 00:45
@GregatGit the if statment is bad?
Greg Duncan
@GregatGit
Jun 15 2017 00:45
@alexandrupintilei first cut it down to size - then add the ...
then return
pursuitgit
@pursuitgit
Jun 15 2017 00:46
@Lanceward410 'toUpperCase at charAt(0)' you can split the array of words into a multi-dimensional array, and then just select the first element in each sub-array and .toUpperCase that
Alex
@alexandrupintilei
Jun 15 2017 00:46
@GregatGit to cut down the size,should i change the param when i call function?
pursuitgit
@pursuitgit
Jun 15 2017 00:46
all you need is .split() and .join()
Greg Duncan
@GregatGit
Jun 15 2017 00:46
@alexandrupintilei no
Alex
@alexandrupintilei
Jun 15 2017 00:47
@GregatGit let me a bit to try
VinayVijayJoshi
@VinayVijayJoshi
Jun 15 2017 00:47
can anyone help on falsy bouncer assignment, my code below, it is removing valid strings as well
function bouncer(arr) {
// Don't show a false ID to this bouncer.
var longWords = arr.filter(function(word){
return ((word !== false) && (word !== null) && (word !== 0) && (word !== "") && (word !== undefined) && (isNaN(word) !== true));
});
return longWords;
}

bouncer(["a", "b", "c"]);
Greg Duncan
@GregatGit
Jun 15 2017 00:47
@alexandrupintilei try to return A-tisket don't worry about anything else - when you have done that add ... to it
mackyking
@mackyking
Jun 15 2017 00:49
Alex
@alexandrupintilei
Jun 15 2017 00:49
i can do that with splice() and right param
mackyking
@mackyking
Jun 15 2017 00:49
Alex
@alexandrupintilei
Jun 15 2017 00:50
if(str.length+1 > 3) etc
i guess
Lance Ward
@Lanceward410
Jun 15 2017 00:51

@pursuitgit

function titleCase(str) {
str = str.toLowerCase();
str = str.split(" ");
for (i=0; i < str.length; i++) {

str[i] = str[i].charAt(0).toUpperCase() + str[i].slice(1) ;

}
return str.join(" ");
}

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

Greg Duncan
@GregatGit
Jun 15 2017 00:51
@alexandrupintilei just make it return the first part 'A-tisket
mackyking
@mackyking
Jun 15 2017 00:51
Greg Duncan
@GregatGit
Jun 15 2017 00:51
@VinayVijayJoshi use Boolean(yourValueHere)
mackyking
@mackyking
Jun 15 2017 00:53
Can anyone help me?
VinayVijayJoshi
@VinayVijayJoshi
Jun 15 2017 00:53
@GregatGit can you elaborate
mackyking
@mackyking
Jun 15 2017 00:53
Alex
@alexandrupintilei
Jun 15 2017 00:54
@GregatGit return str.splice(0, 8);
isnt that the method for 1st part?
Greg Duncan
@GregatGit
Jun 15 2017 00:55
@VinayVijayJoshi Boolean will return true or false which is what you want - so use it in the filter
JD Richards
@jdrichardstech
Jun 15 2017 00:55
@VinayVijayJoshi This is deceivingly easy but really hard. Really look and read & study the helpful links and google these two things. You can solve it in one line of code.
VinayVijayJoshi
@VinayVijayJoshi
Jun 15 2017 00:55
@GregatGit @jdrichardstech Let me do some research..
Greg Duncan
@GregatGit
Jun 15 2017 00:56
@alexandrupintilei Where did you get the number 8 from?
Will Hart
@willhart108
Jun 15 2017 00:56
stuck on the task 'convert celsius to Fahrenheit'. whats the line of code? prob not difficult but it's confusing me..
Alex
@alexandrupintilei
Jun 15 2017 00:56
@GregatGit i returned the first part,but stil dosent work
Will Hart
@willhart108
Jun 15 2017 00:56
Alex
@alexandrupintilei
Jun 15 2017 00:56
number 8 come from 1st index of array
because second argument start count from 1 not 0
Greg Duncan
@GregatGit
Jun 15 2017 00:57
Alex
@alexandrupintilei
Jun 15 2017 00:57
function truncateString(str, num) {
// Clear out that junk in your trunk

return str.slice(0, 8);

}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
returns A-tiscket
Greg Duncan
@GregatGit
Jun 15 2017 00:58
@alexandrupintilei change 8 to however you got 8
@alexandrupintilei and keep it simple return str.slice(0, 8) + '...';
@alexandrupintilei do not use 8
Alex
@alexandrupintilei
Jun 15 2017 01:00
@GregatGit can and what instead of 8?
Greg Duncan
@GregatGit
Jun 15 2017 01:01
@alexandrupintilei however you got 8
Alex
@alexandrupintilei
Jun 15 2017 01:01
i think i stil need to use a if statment
JD Richards
@jdrichardstech
Jun 15 2017 01:01
@willhart108 what is your code at this point?
Greg Duncan
@GregatGit
Jun 15 2017 01:01
@alexandrupintilei no
@alexandrupintilei fix the 8 - its important
Will Hart
@willhart108
Jun 15 2017 01:02
@jdrichardstech none. i don't even know what the code would be
Alex
@alexandrupintilei
Jun 15 2017 01:02
but i dont know why 8 is not good since it give me A-tiscket
mackyking
@mackyking
Jun 15 2017 01:02
Greg Duncan
@GregatGit
Jun 15 2017 01:03
@alexandrupintilei because it wont work with any other test
Will Hart
@willhart108
Jun 15 2017 01:03
@jdrichardstech no examples given before this task. feels out of place and I've been stuck on it for a dau
Greg Duncan
@GregatGit
Jun 15 2017 01:04
@alexandrupintilei did you guess 8?
Alex
@alexandrupintilei
Jun 15 2017 01:04
@GregatGit return str.slice(0, -35) + '...';
stil dont work xD
i didnt guess it,i count
when you said to print A-tiscket only
Greg Duncan
@GregatGit
Jun 15 2017 01:05
@alexandrupintilei what did you count
Long Nguyen
@longnt80
Jun 15 2017 01:05
@willhart108 do you have the formula to convert Celsius to Fahrenheit
VinayVijayJoshi
@VinayVijayJoshi
Jun 15 2017 01:06
@GregatGit @jdrichardstech Thanks. as Richards said very easy once I understood, all falsy values will return false and are taken out
function bouncer(arr) {
// Don't show a false ID to this bouncer.
arr = arr.filter(Boolean);
return arr;
}

bouncer(["a", "b", "c"]);
CamperBot
@camperbot
Jun 15 2017 01:06
vinayvijayjoshi sends brownie points to @gregatgit and @jdrichardstech :sparkles: :thumbsup: :sparkles:
Will Hart
@willhart108
Jun 15 2017 01:07
@longnt80 the screen shot i provided is all I've been given. no examples of how the code would even look
mackyking
@mackyking
Jun 15 2017 01:07
Long Nguyen
@longnt80
Jun 15 2017 01:07
@willhart108 I'm not talking about code yet, do you know the formula to convert?
@VinayVijayJoshi another way:
function bouncer(arr) {
return arr.filter(function(item){return item;});
}
Alex
@alexandrupintilei
Jun 15 2017 01:08
@GregatGit you got the code working?
Will Hart
@willhart108
Jun 15 2017 01:08
@longnt80 celsius x 5/9 + 32
Greg Duncan
@GregatGit
Jun 15 2017 01:08
@alexandrupintilei yes
JD Richards
@jdrichardstech
Jun 15 2017 01:08
@willhart108 so the celsius is what you will be given when the function is invoked as you can see on line 12. it is called celsius as you can see on line 2. so you can say for example in your function….fahrenheit = celsius 2 (celsius times 2). that is not the answer just an example. what you want to do is to say fahernheit is assigned to i.e.(=)... celsius times i.e….()... 9 divided by i.e….(/) …. 5 plus (+) 32
Greg Duncan
@GregatGit
Jun 15 2017 01:08
@alexandrupintilei return str.slice(0, num - str.length) + '...';
Long Nguyen
@longnt80
Jun 15 2017 01:08
@willhart108 so fahrenheit = celsius x 5/9 + 32
VinayVijayJoshi
@VinayVijayJoshi
Jun 15 2017 01:08
@longnt80 can you explain the logic
Will Hart
@willhart108
Jun 15 2017 01:09
so confused
Alex
@alexandrupintilei
Jun 15 2017 01:09
@GregatGit for me,even your code,dosent work
Long Nguyen
@longnt80
Jun 15 2017 01:09
@willhart108 now replace the variables in place of fahrenheit and celsius
@willhart108 wait, your formula is wrong
@willhart108 fahrenheit = celsius x 9/5 + 32
Will Hart
@willhart108
Jun 15 2017 01:11
@longnt80 i know it's better to learn on my own but I'm so frustrated with this task i want to move on. could you provide the line of code?
Greg Duncan
@GregatGit
Jun 15 2017 01:12
@alexandrupintilei return str.slice(0, num - str.length - 1) + '...'; the index starts at 0 (that is why I needed -1)
Long Nguyen
@longnt80
Jun 15 2017 01:12
@willhart108 here's the line of code fahrenheit = celsius * 9/5 + 32;
@willhart108 but what's the point to move on if you don't understand?
Will Hart
@willhart108
Jun 15 2017 01:13
@longnt80 if i see it correctly laid out then ill learn it. all the tasks to this point at least provided an example
Alex
@alexandrupintilei
Jun 15 2017 01:13
@GregatGit stil dosent work
Long Nguyen
@longnt80
Jun 15 2017 01:13
@willhart108 make sure you understand
Huckabee
@huckabee
Jun 15 2017 01:14
Hey im stuck on the Multiple Identical Options in Switch Statements could someone help pleasee switch (val){
case 1:
case 2:
case 3:
result = "Low";
break;
case 4:
case 5:
case 6:
result = "Mid";
break;
case 7:
case 8:
case 9:
result = "High";
break;
}
Greg Duncan
@GregatGit
Jun 15 2017 01:14
@alexandrupintilei how did you get 8 - the same way you get 8 for this problem with give the right number for the next problem
Will Hart
@willhart108
Jun 15 2017 01:14
@longnt80 thank you. i understand doing it on my own.
CamperBot
@camperbot
Jun 15 2017 01:14
willhart108 sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
Huckabee
@huckabee
Jun 15 2017 01:15
nvm got it! :)
Will Hart
@willhart108
Jun 15 2017 01:15
@jdrichardstech thank you as well
CamperBot
@camperbot
Jun 15 2017 01:15
willhart108 sends brownie points to @jdrichardstech :sparkles: :thumbsup: :sparkles:
Alex
@alexandrupintilei
Jun 15 2017 01:15
@GregatGit i allerdy told you,str.splice(0, 8) . The 0 is first index of array whp print "A",and 8 is the eight index of array,BUT now we start the count from 1 NOT 0
that is the splice method
Greg Duncan
@GregatGit
Jun 15 2017 01:16
@alexandrupintilei return str.slice(0, num - 3) + '...';
@GregatGit num is the max length and 3 is less for the '...'
Alex
@alexandrupintilei
Jun 15 2017 01:17
but stil code dont pass
because we need an IF statment,thats my opinion
Greg Duncan
@GregatGit
Jun 15 2017 01:18
@alexandrupintilei it passes the first 2 - it uses the params -
Alex
@alexandrupintilei
Jun 15 2017 01:18
but not all
none from here can help us with this problem? :D
Greg Duncan
@GregatGit
Jun 15 2017 01:19
@alexandrupintilei now you would use if statements - but it you get stuck pass one test at a time
Alex
@alexandrupintilei
Jun 15 2017 01:19
function truncateString(str, num) {
// Clear out that junk in your trunk

if(num.length -1 > 3){

return str.slice(0, 8) + "...";

} else if(num.length > 3){

return res;

} else {

return str;
}

}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
wrong code.w8
Greg Duncan
@GregatGit
Jun 15 2017 01:20
@alexandrupintilei num.length is wrong - its str.length that you need to evalute
mackyking
@mackyking
Jun 15 2017 01:21
Help
Alex
@alexandrupintilei
Jun 15 2017 01:26
@GregatGit i dont know the right condition
mackyking
@mackyking
Jun 15 2017 01:28
I'm stuck in that challenge...
Huckabee
@huckabee
Jun 15 2017 01:29
function isLess(a, b) {
// Fix this code
return a === b;
}
// Change these values to test
isLess(15, 10);
fdemaa
@fdemaa
Jun 15 2017 01:29
can anyone help me to understand how this loops works on the array and then on the sub array
var arr = [
[1,2], [3,4], [5,6]
];
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}
mackyking
@mackyking
Jun 15 2017 01:29

function nextInLine(arr, item) {

return item; // Change this line
}

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

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

Huckabee
@huckabee
Jun 15 2017 01:30
My code keeps failing I can’t see why it is fine for the is less (15,10) but not (10,15)
function isLess(a, b) {
// Fix this code
return a === b;
}
// Change these values to test
isLess(15, 10);
Christopher McCormack
@cmccormack
Jun 15 2017 01:32
@huckabee === means they are equal to each other
@huckabee 15 is not less than 10 so it would return false if you were using the correct equality comparison, but 15 === 10 is also false
Manish Giri
@Manish-Giri
Jun 15 2017 01:33
@huckabee you need to check if a is less than b or not
as the function name isLess indicates.
mackyking
@mackyking
Jun 15 2017 01:34
Help....

function nextInLine(arr, item) {

return item; // Change this line
}

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

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

Christopher McCormack
@cmccormack
Jun 15 2017 01:34
@mackyking help with what? You haven't started.
Long Nguyen
@longnt80
Jun 15 2017 01:34
Huckabee
@huckabee
Jun 15 2017 01:35
@Manish-Giri ahh got it thanks!
CamperBot
@camperbot
Jun 15 2017 01:35
huckabee sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5983 | @manish-giri |http://www.freecodecamp.com/manish-giri
Huckabee
@huckabee
Jun 15 2017 01:35
@cmccormack thanks!
CamperBot
@camperbot
Jun 15 2017 01:35
huckabee sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
fdemaa
@fdemaa
Jun 15 2017 01:36
@longnt80 :clap: Thanks long!
CamperBot
@camperbot
Jun 15 2017 01:36
fdemaa sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
Lance Ward
@Lanceward410
Jun 15 2017 01:38
If I just started learning to code a couple months ago, how long do you think I have before I am able to build my own Tesla
dascreator
@dascreator
Jun 15 2017 01:39
having a really tough time figuring out how the escape sequences work...
Danielfro5
@Danielfro5
Jun 15 2017 01:39
https://cpy.pt/5L9b3SKM
would anyone have any hints as to why this if statement is firing when the object
seems to contain a "tracks" property?
Christopher McCormack
@cmccormack
Jun 15 2017 01:39
@Lanceward410 only 140 lines of CSS or so https://codepen.io/squints/pen/dPoXQW
dascreator
@dascreator
Jun 15 2017 01:39
Challenge is to create this:
FirstLine
\SecondLine\
ThirdLine
"'FirstLine\n'\secondLine\'\rThirdLine'";
Christopher McCormack
@cmccormack
Jun 15 2017 01:40
@Danielfro5 not sure if anyone wants to click that link or not...
fdemaa
@fdemaa
Jun 15 2017 01:40
you have to add two more backslash
Lance Ward
@Lanceward410
Jun 15 2017 01:40
Loll
dascreator
@dascreator
Jun 15 2017 01:41
i did that, but not showing up when I copy and paste
Lance Ward
@Lanceward410
Jun 15 2017 01:41
@cmccormack I second that
fdemaa
@fdemaa
Jun 15 2017 01:41
@dascreator check the quotes
Christopher McCormack
@cmccormack
Jun 15 2017 01:42
@Danielfro5 can you paste the snippet here?

Code goes here.

dascreator
@dascreator
Jun 15 2017 01:42
@fdemaa I have tried every variation I can think of without luck.
Danielfro5
@Danielfro5
Jun 15 2017 01:43


//JSON sample...

"2468": {

"album": "1999",

"artist": "Prince",

"tracks": [

"1999",

"Little Red Corvette"

]

},

if (!collection[id].hasOwnProperty("tracks")){

//2.this^ is firing when  objecthasownproperty?)

collection[id][propVar] = [];

}
sorry about that ^ would anyone have any hints as to why this if statement is firing when the object
seems to contain a "tracks" property?
Christopher McCormack
@cmccormack
Jun 15 2017 01:45
@dascreator characters are escaped by using \ before a letter or symbol. For example \n is a newline character, \r a carriage return, and if you just want to add a \, you can escape the backslash as well: \\
Danielfro5
@Danielfro5
Jun 15 2017 01:46
btw propVar just = "tracks" forgot to change for display purposes
dascreator
@dascreator
Jun 15 2017 01:47
var myStr = "FirstLine\n\secondLine\\rThirdLine";
fdemaa
@fdemaa
Jun 15 2017 01:47
you have to put backslash on second line
\\    backslash
dascreator
@dascreator
Jun 15 2017 01:48
@fdemaa @cmccormack That's what I have but wiht two backlashes before and after secondLine... it doesnt show when I send in chat room. Not sure what I am missing based on what was described above.
Christopher McCormack
@cmccormack
Jun 15 2017 01:48
@dascreator put your code in between backticks so it doesn't try to parse it as markdown.  code
fdemaa
@fdemaa
Jun 15 2017 01:48
put the code
like this
dascreator
@dascreator
Jun 15 2017 01:49
Christopher McCormack
@cmccormack
Jun 15 2017 01:49
@dascreator Should S be capitalized?
fdemaa
@fdemaa
Jun 15 2017 01:50
put the words on camelCase
@dascreator
Somia ♡
Jun 15 2017 01:50
I need help with Using Objects for Lookups!
dascreator
@dascreator
Jun 15 2017 01:51
technically the challenge shows regular case, but it doesnt seem to make a difference with this challenge.
Christopher McCormack
@cmccormack
Jun 15 2017 01:51
Pretty sure it does
dascreator
@dascreator
Jun 15 2017 01:52
unbelieveable.... you were right @cmccormack thanks man!
CamperBot
@camperbot
Jun 15 2017 01:52
dascreator sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
Christopher McCormack
@cmccormack
Jun 15 2017 01:52
@somiajagadish what do you have so far?
@dascreator :thumbsup:
Somia ♡
Jun 15 2017 01:53
@cmccormack nothing yet.. i'm confused with the example it shows me and how to put that into my code
Christopher McCormack
@cmccormack
Jun 15 2017 01:54
@somiajagadish just remember there are two ways to look up values in an object - dot notation which uses the ACTUAL name of the object property, and bracket notation that allows you to pass a variable or a string literal
fdemaa
@fdemaa
Jun 15 2017 01:55
@cmccormack chris the length property start counting on 1 right ?
Christopher McCormack
@cmccormack
Jun 15 2017 01:55
var object = { property: 'value' };
object.property // 'value'
object['property'] // 'value'
var temp = 'property'
object[temp] // 'value'
Somia ♡
Jun 15 2017 01:56
@cmccormack i know that, lol. but they want me to convert a switch statement into a lookup table and use it to look up val and assign the associates\d string to the result variable.
Joseph
@revisualize
Jun 15 2017 01:56

You have to assign 'FirstLine newline backslash SecondLine backslash carriage-return ThirdLine' to the variable myStr.
But, You have to replace the escape words with the proper escape sequences. (And per the instructions: remove all spaces.)
How do you escape a newline? With: \n
How do you escape a backslash? With: \\
How do you escape a carriage-return? With \r
So, you have break the problem down.
FirstLine newline backslash SecondLine backslash carriage-return ThirdLine
FirstLine \n backslash SecondLine backslash carriage-return ThirdLine
FirstLine \n \\ SecondLine backslash carriage-return ThirdLine
FirstLine \n \\ SecondLine \\ carriage-return ThirdLine
FirstLine \n \\ SecondLine \\ \r ThirdLine
You have to follow the instructions and remove all of the spaces
Then assign that to myStr as a string.

This lesson is not trying to teach you how to get some green check marks to pass onto the next lesson. It is trying to teach you a really valuable skill. If you have a string in JavaScript that is instantiated with double quotes (") (Example: var myStr = "Hello World";) you can also instantiate a string with single quotes (') (Example: var myStr = 'Hello World';)

How do you add a " to that string? Let's say you instantiated the string with double quotes and you want to put in a quote that someone said. You have to use an escape character.
Example: var myQuote = "Happy Feet said, \"I really like the rhythm.\"";
Or what happens if you want to add a tab to your string? You can't really add 3 spaces and expect it to show up as a tab. You have to use the escape character for a tab (\t).

OR let's say your trying to output a bunch of text and paragraphs within your JavaScript string. You can't really just make a bunch of variables.
var myParagraph1 = "a bunch of characters";
var myParagraph2 = "a bunch more characters";
I mean you could... but, why not just:
var myStr = "A bunch of characters/sentences.\nThe second paragraph of characters and sentences.";

Somia ♡
Jun 15 2017 01:56
*associated
Lance Ward
@Lanceward410
Jun 15 2017 01:56
woah
Christopher McCormack
@cmccormack
Jun 15 2017 01:56
@fdemaa length gives the total number of values, it's stored as part of an array
Kyle Holm
@thekholm80
Jun 15 2017 01:56
any redux gurus here?
Joseph
@revisualize
Jun 15 2017 01:56
Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
Somia ♡
Jun 15 2017 01:57
@Lanceward410 ahaha that was my reaction too :laughing:
fdemaa
@fdemaa
Jun 15 2017 01:57
wtf
nice @revisualize
Lance Ward
@Lanceward410
Jun 15 2017 01:59
@somiajagadish Just consider that the switch statement and lookup Object both serve the same purpose. They will have similar parts but different syntax. So each will have a "Case" / "key" with a following "result" / "value"
Vicky Lai
@vickylai
Jun 15 2017 02:00
How to get an object out of an array? Map the debris challenge. ie: orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);
Lance Ward
@Lanceward410
Jun 15 2017 02:00
@somiajagadish Your lookup variable won't have "break;"s in it. But it will have the same Keys and Values that correspond to the switch statement's Cases and Results
Joseph
@revisualize
Jun 15 2017 02:00
@vickylaiio just access the array element.
Vicky Lai
@vickylai
Jun 15 2017 02:00
@revisualize arguments[0] didn't seem to work..
Joseph
@revisualize
Jun 15 2017 02:01
That should give you the whole array element
Vicky Lai
@vickylai
Jun 15 2017 02:01
@revisualize Gah. Yeah ok. Got it. Thanks for being my duck
CamperBot
@camperbot
Jun 15 2017 02:01
vickylaiio sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4165 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Jun 15 2017 02:02
Im a motherf'ing goose
Somia ♡
Jun 15 2017 02:02
@Lanceward410 oh okay thankss
CamperBot
@camperbot
Jun 15 2017 02:02
somiajagadish sends brownie points to @lanceward410 :sparkles: :thumbsup: :sparkles:
Lance Ward
@Lanceward410
Jun 15 2017 02:03
thanks @camperbot
CamperBot
@camperbot
Jun 15 2017 02:03
lanceward410 sends brownie points to @camperbot :sparkles: :thumbsup: :sparkles:
:star2: 3320 | @camperbot |http://www.freecodecamp.com/camperbot
Joseph
@revisualize
Jun 15 2017 02:04
Thanks @revisualize
CamperBot
@camperbot
Jun 15 2017 02:04
sorry revisualize, you can't send brownie points to yourself! :sparkles: :sparkles:
Joseph
@revisualize
Jun 15 2017 02:05
You bucket of rust!
Somia ♡
Jun 15 2017 02:05
@revisualize thanks
CamperBot
@camperbot
Jun 15 2017 02:05
somiajagadish sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4166 | @revisualize |http://www.freecodecamp.com/revisualize
Somia ♡
Jun 15 2017 02:05
ur welcomeeee
ahaha
Joseph
@revisualize
Jun 15 2017 02:05
CamperBot
@camperbot
Jun 15 2017 02:05
revisualize sends brownie points to @somiajagadish :sparkles: :thumbsup: :sparkles:
Somia ♡
Jun 15 2017 02:06
ahaha thankss
pursuitgit
@pursuitgit
Jun 15 2017 02:06
Hi friends, can anyone help with 'Return Largest Numbers in Arrays' I'd just like some help with direction not the completed code. Here is my code for reference

function largestOfFour(arr) {
// You can do this!
var largestNumber = 0;

for (i = 0; i < arr.length; i++)
{
var subArray = arr[i];
for (var j=0; j < subArray.length; ++j)
{
if (subArray[j] > largestNumber) {
largestNumber = subArray[j];
return largestNumber;
}
}
}
return arr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
can anyone tell me if I am getting close?
sonnguyen2603
@sonnguyen2603
Jun 15 2017 02:12
function convertToRoman(num) {
return num;
}

convertToRoman(36);
With this problem can anyone tell me how should I start?
@haseebuchiha
Jun 15 2017 02:14
Now try it yourself! Modify the Bike constructor to have a private property called gear and two public methods called getGear and setGear to get and set that value.
can someone please explain this to me
Gulsvi
@gulsvi
Jun 15 2017 02:15
@pursuitgit When you return inside of a for loop, it exits the function. You're getting close, but you are running return largestNumber too soon.
@haseebuchiha
Jun 15 2017 02:18
?
Kyle Holm
@thekholm80
Jun 15 2017 02:19
do any of you know anything about redux?
pursuitgit
@pursuitgit
Jun 15 2017 02:21
@SkyC0der hmm ok I see where I need to run the return now, I've tried a different approach and think I am even closer! Could you possibly help with this at all?

function largestOfFour(arr) {
// You can do this!
var newArray = [];

for (i = 0; i < arr.length; ++i)
{
var largestNumber = -Infinity;
for (var j=0; j < arr[i].length; ++j)
{
if (arr[i][j] > largestNumber)
{
largestNumber = arr[i][j];
newArray.push(largestNumber);
}

}

}
return newArray;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
@haseebuchiha
Jun 15 2017 02:21
??
?
Gulsvi
@gulsvi
Jun 15 2017 02:25
@pursuitgit You're still kind of doing the same thing - when your second loop runs, it says "hmmm, is 4 greater than 0? Yes, it is. Push it to the array."
It then does it again when it gets to the '5'
and again when it gets to the 13
and so on...
@haseebuchiha
Jun 15 2017 02:25
?
Eric
@tehnwegyu
Jun 15 2017 02:26

var myVar = 87;

// Only change code below this line
myVar = myVar ++;
why dosent it equal 88

Gulsvi
@gulsvi
Jun 15 2017 02:26
@haseebuchiha You're going to have to be patient - if someone can help you, they will
pursuitgit
@pursuitgit
Jun 15 2017 02:27
@SkyC0der hmm ok, so perhaps I need to change my checking logic?
@SkyC0der could I just remove the previous maximum number from my newArray if there is a new maximum?
Gulsvi
@gulsvi
Jun 15 2017 02:28
@pursuitgit You could do that, yes. Performance will take a hit though.
I liked it the way you had it before - you were just returning too early
pursuitgit
@pursuitgit
Jun 15 2017 02:30
@SkyC0der ok cool I see what you mean, I've fixed it now and it's definitely returning the largest number. I just have to turn it into an array now and make sure it keeps looping through the rest
function largestOfFour(arr) {
// You can do this!
var largestNumber = 0;

for (i = 0; i < arr.length; i++)
{
var subArray = arr[i];
for (var j=0; j < subArray.length; ++j)
{
if (subArray[j] > largestNumber) {
largestNumber = subArray[j];

}
}
return largestNumber;
}
return arr;
}
Eric
@tehnwegyu
Jun 15 2017 02:31
nevermind i figured it out
Gulsvi
@gulsvi
Jun 15 2017 02:32
@pursuitgit You're really, really close now :)
pursuitgit
@pursuitgit
Jun 15 2017 02:33
@SkyC0der haha I can feel it, it's so frustrating! thanks for the help :clap:
CamperBot
@camperbot
Jun 15 2017 02:33
pursuitgit sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 1709 | @skyc0der |http://www.freecodecamp.com/skyc0der
Gulsvi
@gulsvi
Jun 15 2017 02:33
@pursuitgit Can't really give any other hints without giving away the answer. :) I'm not sure what coding environment you're using, but sometimes it helps to see what's happening on each loop with a console.log()
I used codepen for most of my JS algorithms, there's also http://www.pythontutor.com/visualize.html#mode=edit
pursuitgit
@pursuitgit
Jun 15 2017 02:36
hmm ok, I've just been using the freecodecamp exercise pages @SkyC0der can I use the google JS console or is codepen better?
Cathy
@cathypchui
Jun 15 2017 02:36
Hi, I've been working on this for hours trying to figure it out and I don't know what I'm doing wrong. It's the profileLookup lesson/challenge

//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(i=0; i<contacts.length; i++){
if(contacts[i].firstName == firstName){
if(contacts[i].hasOwnProperty(prop)===true){
return(contacts[i].prop);
}
else{
return("No such property");
}
}
else{
return("No such contact");
}
}
// Only change code above this line
}

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

pursuitgit
@pursuitgit
Jun 15 2017 02:36
@cathypchui use  either at the top and bottom of your code to make it more readable :)
like this
Gulsvi
@gulsvi
Jun 15 2017 02:37
@pursuitgit The google chrome console is great - I haven't take a lot of time to learn it, but from the little I have used it, seems like a good tool
Cathy
@cathypchui
Jun 15 2017 02:37
//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(i=0; i<contacts.length; i++){
if(contacts[i].firstName == firstName){
if(contacts[i].hasOwnProperty(prop)===true){
return(contacts[i].prop);
}
else{
return("No such property");
}
}
else{
return("No such contact");
}
}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Curtis
@CurtisJCamp
Jun 15 2017 02:38
Hey can anybody help me with escaping quotes?
Christopher McCormack
@cmccormack
Jun 15 2017 02:38
@cathypchui you're returning No such contact after the first contact that doesn't match
@cathypchui and just FYI - this is redundant - contacts[i].hasOwnProperty(prop)===true - hasOwnProperty returns a true or a false already so you don't need to test for equivalency, you're basically saying true === true, which is the same as true
Cathy
@cathypchui
Jun 15 2017 02:40
I realize that using return means the for loop ends, but I couldn't find another way to access the inside of the array for all the arrays inside the contacts array
I tried replacing return with console.log() but it didn't work
Joseph
@revisualize
Jun 15 2017 02:42
@cathypchui youre returning no contact toooooooo early.
Christopher McCormack
@cmccormack
Jun 15 2017 02:42
@cathypchui just move the return outside your loop
Joseph
@revisualize
Jun 15 2017 02:43
Let's say you were at a big business event and you're quite popular (with all those skills you have) throughout the event you got handed 200 business cards (Which will remain unordered). Now, I walk up to you at the end and ask you.. Do you have a Business Card for "Jane Smith"? Now you loop look through your stack of 200 business cards. When would you tell me that you didn't have a business card for Jane?
....
So, you're saying that after you loop look through all of the contacts cards in your array of object stack. That you'd tell me you don't have one for the individual?
  // code before a for loop.
for (..........) {
// Code inside of a for loop.
}
// code after a for loop.
...
Cathy
@cathypchui
Jun 15 2017 02:44
Yeah, I understand the logic, just not how to go about writing it
Joseph
@revisualize
Jun 15 2017 02:44
Sorry for the spammyness... i am at a meetup
Move no contact out of the for


I cant do multi line from my phone.
for (.....) { .... }; return "no contact";}
Crap that last } is supposed to be a 
Vicky Lai
@vickylai
Jun 15 2017 02:47
Hey yall. Why's my for loop not triggering?
function orbitalPeriod(arr) {
console.log(arguments[0][0]['name']);
var arr = [];

for (var teapot = 0; teapot < arguments[0].length; teapot++) {
console.log(arguments[0][teapot]);
var GM = 398600.4418;
var avgAlt = arguments[0][teapot]['avgAlt'];
var name = arguments[0][teapot]['name'];
var orbitalPeriod = 2*Math.PI*(Math.sqrt(Math.pow((earthRadius + avgAlt),3)/GM));
var result = {
name : name,
orbitalPeriod : Math.round(orbitalPeriod)
}
arr.push(result);
}

return arr;
}
Joseph
@revisualize
Jun 15 2017 02:48
www
Pythontutor.com
Crap!
@vickylaiio -----^^^^^
Christopher McCormack
@cmccormack
Jun 15 2017 02:48
@vickylaiio are you passing arguments to your function?
Vicky Lai
@vickylai
Jun 15 2017 02:49
@cmccormack Yep
Joseph
@revisualize
Jun 15 2017 02:49
Gittering from your phone kind of sucks.
Christopher McCormack
@cmccormack
Jun 15 2017 02:50
@revisualize haha
VinayVijayJoshi
@VinayVijayJoshi
Jun 15 2017 02:50
why my array 'narr' is not getting sorted

function getIndexToIns(arr, num) {
// Find my place in this sorted array.
narr = Array.from(arguments).splice(0,1);
console.log("@@ " + narr);
narr.sort(function(a, b) {
return a-b;
});

console.log("## " + narr);
return num;
}

getIndexToIns([5, 3, 20, 3], 5);
Christopher McCormack
@cmccormack
Jun 15 2017 02:51
@vickylaiio what is the exercise called?
Joseph
@revisualize
Jun 15 2017 02:51
WTF ... why is everyone using arguments ... when they have freaking parameters that hold the same value?
Joseph
@revisualize
Jun 15 2017 02:51
USE YOUR FUCKING PARAMETERS OF YOU HAVE THEM
Hashtag-rant
Cathy
@cathypchui
Jun 15 2017 02:53
the fact that I didn't even fully understand what you're ranting about indicates you're probably speaking from a position of experience, heh. Maybe bring it up with the people building FCC.
Christopher McCormack
@cmccormack
Jun 15 2017 02:54
@vickylaiio is it not logging anything in the loop? Also like @revisualize says, you can use the function parameter arr instead of arguments
Joseph
@revisualize
Jun 15 2017 02:55
I used to be a newb just like everyone else.
Vicky Lai
@vickylai
Jun 15 2017 02:55
@cmccormack Yeah, the first console.log shows up but not the second
Manish Giri
@Manish-Giri
Jun 15 2017 02:55
USE YOUR FUCKING PARAMETERS OF YOU HAVE THEM
Bryan Reese
@breese8009
Jun 15 2017 02:55
lmao ^
Joseph
@revisualize
Jun 15 2017 02:55
@cathypchui you'll hopefull inderstand what I'm talking about in a few weeks.
Manish Giri
@Manish-Giri
Jun 15 2017 02:55
if they knew what parameters/arguments were, they wouldn't be here in the first place
so, chill.
Christopher McCormack
@cmccormack
Jun 15 2017 02:56
FCC explains it fine in Passing Values to Functions with Arguments, it's just it takes some time to lock in the names and use of different features
Cathy
@cathypchui
Jun 15 2017 02:56
right? That's what I mean. Chill? If everyone with more experience just yelled in here I'd go somewhere else.
pursuitgit
@pursuitgit
Jun 15 2017 02:56
hey friends can anyone help me with this, I've been stuck on it for 20 minutes

function largestOfFour(arr) {
// You can do this!
var largestNumber = 0;
var newArr = [];

for (i = 0; i < arr.length; ++i)
{
var subArray = arr[i];
for (var j=0; j < subArray.length; ++j)
{
if (subArray[j] > largestNumber) {
largestNumber = subArray[j];
newArr.push(largestNumber);
}
}

}
return newArr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Manish Giri
@Manish-Giri
Jun 15 2017 02:56
yeah, don't pay attention. Keep learning! @cathypchui
pursuitgit
@pursuitgit
Jun 15 2017 02:57
not looking for the answer just some direction
Joseph
@revisualize
Jun 15 2017 02:57
@Manish-Giri i was trying to be psuedo-funny. I have seen it a LOT lately that people dont seem to want to use the parameters of their function but, are using the argumemts object.
Vicky Lai
@vickylai
Jun 15 2017 02:58
@cmccormack Just got it working. I went and named my result array the same as the function argument. Doh.
Christopher McCormack
@cmccormack
Jun 15 2017 02:58
@vickylaiio more likely your loop log statement is the only one showing up, you can't reference an index of an object:
> var arr = [{a: 'a', b: 'b'}]
> arr[0][0]
undefined
Bryan Reese
@breese8009
Jun 15 2017 02:58
holler back
CamperBot
@camperbot
Jun 15 2017 02:58
holler back!
Christopher McCormack
@cmccormack
Jun 15 2017 02:58
@vickylaiio :thumbsup:
@pursuitgit you're pushing largestNumber every time a number is larger, but that isn't quite what is expected
Kevin Peña
@kebien6020
Jun 15 2017 03:00
@cmccormack Well, technically you can, since arrays are just objects.
> var obj = {'0': 'a', '1': 'b'}
> obj[0]
"a"
Manish Giri
@Manish-Giri
Jun 15 2017 03:00
@revisualize okay, I understand your point. But it just comes across as yelling, plain and simple.
pursuitgit
@pursuitgit
Jun 15 2017 03:01
@cmccormack do I perhaps need to push the largestNumber in the other for loop?
grace
@graciphine
Jun 15 2017 03:01
whats the point of using "//" to ignore the remainder of the text after it than just not writing it at all
pursuitgit
@pursuitgit
Jun 15 2017 03:01
@cmccormack or do I need to work on my syntax
Christopher McCormack
@cmccormack
Jun 15 2017 03:01
@kebien6020 technically your 0 was coerced into a string, but that isn't what she was trying to do
@pursuitgit you need to compare all numbers in the subarray before pushing anything into newArray
Kevin Peña
@kebien6020
Jun 15 2017 03:02
@cmccormack That is correct, but also technically your 0 is also coerced to string.
> var arr = ['a', 'b']
> arr['0']
"a"
Christopher McCormack
@cmccormack
Jun 15 2017 03:03
@kebien6020 yup, and it would fail because there is no index on an object.
pursuitgit
@pursuitgit
Jun 15 2017 03:03
@cmccormack hmm ok I think I'm on the right track just one test left that isn't passing.

function largestOfFour(arr) {
// You can do this!
var largestNumber = 0;
var newArr = [];

for (i = 0; i < arr.length; ++i)
{
var subArray = arr[i];
for (var j=0; j < subArray.length; ++j)
{
if (subArray[j] > largestNumber)
{
largestNumber = subArray[j];

}

}
newArr.push(largestNumber);
}
return newArr;
}

largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Christopher McCormack
@cmccormack
Jun 15 2017 03:05
@pursuitgit I highly recommend you put your opening braces on the same line as your statements. There are cases where if you don't the code block may be interpreted as a statement instead of an expression and cause issues
pursuitgit
@pursuitgit
Jun 15 2017 03:05
@cmccormack this returns [27, 27, 39, 1001] when it should return [27, 5, 39, 1001]. so close! thanks
CamperBot
@camperbot
Jun 15 2017 03:05
pursuitgit sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
Christopher McCormack
@cmccormack
Jun 15 2017 03:05
@pursuitgit yup it's almost as if you didn't clear the variable before moving to the next array :)
Emmanx
@Emmanx
Jun 15 2017 03:05
I have zero idea on how to approach the Build a pomodoro clock project
Christopher McCormack
@cmccormack
Jun 15 2017 03:06
@Emmanx are you aware of the setInterval function?
Emmanx
@Emmanx
Jun 15 2017 03:06
Can anyone available guide me through please
pursuitgit
@pursuitgit
Jun 15 2017 03:06
@cmccormack hmm ok, I thought putting them on the next line helped with readability. I'll keep that in mind in the future
@cmccormack haha I got it, ok I was so close I'm retarded! thanks for the help
CamperBot
@camperbot
Jun 15 2017 03:07
pursuitgit sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: pursuitgit already gave cmccormack points
Kevin Peña
@kebien6020
Jun 15 2017 03:07
@Emmanx I usually start my projects by drawing (in paper, or paint) the main screen of the project. And trying to imagine what would it do. (Not how would it work)
pursuitgit
@pursuitgit
Jun 15 2017 03:07
@cmccormack

function largestOfFour(arr) {
// You can do this!

var newArr = [];

for (i = 0; i < arr.length; ++i) {
var subArray = arr[i];
var largestNumber = 0;
for (var j=0; j < subArray.length; ++j) {
if (subArray[j] > largestNumber) {
largestNumber = subArray[j];

}

}
newArr.push(largestNumber);

}
return newArr;
}

largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Emmanx
@Emmanx
Jun 15 2017 03:07
@cmccormack yes I am
Christopher McCormack
@cmccormack
Jun 15 2017 03:08
@pursuitgit just be aware there may be unintended pitfalls, otherwise code as you wish. https://stackoverflow.com/questions/7723492/strange-behavior-of-return-statement-in-javascript
@Emmanx ok you'll want to use that for your actual timer. Provide a way for users to modify their break and session times, to start and stop the clock.
@Emmanx start writing out some pseudocode, refine it, and fill in the sections with actual code
Emmanx
@Emmanx
Jun 15 2017 03:10
OK thanks
Joseph
@revisualize
Jun 15 2017 03:19
Lalalal
Long Nguyen
@longnt80
Jun 15 2017 03:20

@Emmanx

I have zero idea on how to approach the Build a pomodoro clock project

research setInterval, setTimeout, and the Date object

JD Richards
@jdrichardstech
Jun 15 2017 03:31

Working on Sum All Odd Fibonacci Numbers
Instructions:
Given a positive integer num, return the sum of all odd Fibonacci numbers that are less than or equal to num.

The first two numbers in the Fibonacci sequence are 1 and 1. Every additional number in the sequence is the sum of the two previous numbers. The first six numbers of the Fibonacci sequence are 1, 1, 2, 3, 5 and 8.

For example, sumFibs(10) should return 10 because all odd Fibonacci numbers less than 10 are 1, 1, 3, and 5.

I pass every test except: sumFibs(75025) should return 135721.

My code:

function sumFibs(num) {
let arr = [1,1]
let tmp = 0
let count = 1

while(arr[arr.length-1]<num && (arr[count] + arr[count-1]) < num){
tmp = arr[count] + arr[count-1]
arr.push(tmp)
count++
}

let newArr = arr.filter((num2)=>{
return num2 %2 !==0
})
console.log("oddNumberArray: ", newArr)

let sumArray = newArr.reduce((currVal, num3)=>{
return currVal + num3
})

return sumArray;
}

Can’t understand why I don’t pass test….sumFibs(75025) should
return 135721

Junou Cui
@FIRESTROM
Jun 15 2017 03:34
Hi guys ! Is there a easier way to solve the "Smallest Common Multiple" problem??
Joseph
@revisualize
Jun 15 2017 03:35
@jdrichardstech
JD Richards
@jdrichardstech
Jun 15 2017 03:37
@revisualize thanks!
CamperBot
@camperbot
Jun 15 2017 03:37
jdrichardstech sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4168 | @revisualize |http://www.freecodecamp.com/revisualize
Gurpreet SIngh
@Gurpreet3131
Jun 15 2017 03:40
How can I load text from a text, into <p> html tag in handlebars, in expressjs?
from a textfile
Bethany Roberts
@Betanya
Jun 15 2017 03:41
I have two statements but I am still trying to figure out how to make the
output the count and "Hold/Bet". Let me give the 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 "J":
case "Q":
case "K":
case "A":
count--;break
};

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

// Only change code above this line
}

// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
Moisés Man
@moigithub
Jun 15 2017 03:42
@Betanya add space before Bet or Hold
soo it doesnt read like 1Bet but 1 Bet
Bethany Roberts
@Betanya
Jun 15 2017 03:42
@moigithub let me try!
@moigithub I still didn't pass it
Toby J. Henderson
@Mr-Henderson
Jun 15 2017 03:43


nction caseInSwitch(val) {
// Only change code below this line
switch(exp) {
case 1:
console.log("alpha");
break;
case 2:
consol.log("beta");
case 3:
console.log("gamma");
break;
case 4:
console.log("delta");

}
// Only change code above this line
}

// Change this value to test
caseInSwitch(1);
 No clue what Im doing please help

Moisés Man
@moigithub
Jun 15 2017 03:43
i think case 10 missing ? @Betanya (dont remember)
Toby J. Henderson
@Mr-Henderson
Jun 15 2017 03:44
nction caseInSwitch(val) {
// Only change code below this line
switch(exp) {
case 1:
console.log("alpha");
break;
case 2:
consol.log("beta");
case 3:
console.log("gamma");
break;
case 4:
console.log("delta");
}
// Only change code above this line
}
// Change this value to test
caseInSwitch(1);
Moisés Man
@moigithub
Jun 15 2017 03:44
@Mr-Henderson u should evaluate nction caseInSwitch(val) { <--- val variable/parameter
NOT exp
and set ur strings "alpha" etc to answer variable (dont use console.log)
Bethany Roberts
@Betanya
Jun 15 2017 03:45
@moigithub oh haha it was, but I still didn't pass D:
Toby J. Henderson
@Mr-Henderson
Jun 15 2017 03:45
hmmm like var = "alpha"?
let me mess with it for a few mins brb
Long Nguyen
@longnt80
Jun 15 2017 03:48
Bethany Roberts
@Betanya
Jun 15 2017 03:48
@moigithub I got it! Left off a =! :D Thanks!!
CamperBot
@camperbot
Jun 15 2017 03:48
betanya sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3370 | @moigithub |http://www.freecodecamp.com/moigithub
Bethany Roberts
@Betanya
Jun 15 2017 03:49
Also, why did it have me send brownie points, what do they do lol
mackyking
@mackyking
Jun 15 2017 03:50
I need help...
Kevin Holmes
@codersc
Jun 15 2017 03:50
what's up @mackyking
Toby J. Henderson
@Mr-Henderson
Jun 15 2017 03:50

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

}
// Only change code above this line
}

// Change this value to test
caseInSwitch(1);
ahhh @longnt80 thanks
CamperBot
@camperbot
Jun 15 2017 03:51
mr-henderson sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
mackyking
@mackyking
Jun 15 2017 03:51
Kevin Holmes
@codersc
Jun 15 2017 03:51
?
Toby J. Henderson
@Mr-Henderson
Jun 15 2017 03:52
I get it now lol
Christopher McCormack
@cmccormack
Jun 15 2017 03:52
@Betanya you said thanks and mentioned his name :) it's a bot. It does nothing but show your progress/gratitude from others
mackyking
@mackyking
Jun 15 2017 03:52
Last part... I cant do it...
@codersc
Kevin Holmes
@codersc
Jun 15 2017 03:53
@mackyking you just posted a link to this chat room. im not sure what you mean
Gurpreet SIngh
@Gurpreet3131
Jun 15 2017 03:53
how to import text in p tag from a text file?
mackyking
@mackyking
Jun 15 2017 03:53
After nextInLine(testArr, 10), testArr[4] should be 10
Kevin Holmes
@codersc
Jun 15 2017 03:53
which challenge? @mackyking
mackyking
@mackyking
Jun 15 2017 03:54

function nextInLine(arr, item) {
arr.push(item);
return arr[0];

// Change this line
}

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

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

Kevin Holmes
@codersc
Jun 15 2017 03:55
anyone know how to get the bot to post how to format code?
Christopher McCormack
@cmccormack
Jun 15 2017 03:55
'''
CamperBot
@camperbot
Jun 15 2017 03:55
:bulb: to format code use backticks!  more info
mackyking
@mackyking
Jun 15 2017 03:55
I am stuck in the last part...
Kevin Holmes
@codersc
Jun 15 2017 03:56
@mackyking post your in between three backticks (the key to the left of the 1)
Christopher McCormack
@cmccormack
Jun 15 2017 03:56

Code goes here, backticks go on their own line. Previous posts can be edited.

meslance
@meslance
Jun 15 2017 03:56
Do you need to use console.log for "Return Early Pattern for Functions"?
Mukul Agrawal
@mukul09
Jun 15 2017 03:57
@mackyking after pushing the item in your array you have to remove the 1st element from the array using .shift() method
Kevin Holmes
@codersc
Jun 15 2017 03:57
@mackyking var foo = 'bar'; that's what formatted code looks like
makes it easier to reead so we can help
@meslance no you don't
mackyking
@mackyking
Jun 15 2017 03:59
Wait guys... Thanks for the respond.. I love it...
meslance
@meslance
Jun 15 2017 04:05
@codersc Ok, thank you.
CamperBot
@camperbot
Jun 15 2017 04:05
meslance sends brownie points to @codersc :sparkles: :thumbsup: :sparkles:
Jun 15 2017 04:08

//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(firstName==contacts[i].firstName){
if(contacts[i].prop==prop){
return contacts[i].prop;
}else{
return "No such property";
}
}else{
return "No such contact";
}
}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "number");
what is wrong with my code?

Joseph
@revisualize
Jun 15 2017 04:09
Returning no contact toooooooo early
Also
Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
mackyking
@mackyking
Jun 15 2017 04:11
function nextInLine(arr, item) { // Your code here arr.push(item); arr.shift(item); return arr[0]; // Change this line } // Test Setup var testArr = [1,2,3,4,5]; // Display Code console.log("Before: " + JSON.stringify(testArr)); console.log(nextInLine(testArr, 6)); // Modify this line to test console.log("After: " + JSON.stringify(testArr));
Jun 15 2017 04:11
@revisualize i can't understand can u explain more clearly
mackyking
@mackyking
Jun 15 2017 04:11
Jun 15 2017 04:12
@mackyking u did not push element arr.push()
Mukul Agrawal
@mukul09
Jun 15 2017 04:12
mackyking
@mackyking
Jun 15 2017 04:12
Where is the element exactly?
NSS534
@NSS534
Jun 15 2017 04:19

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
var convertTemp = celsius;
var convertToF = convertTemp * 9 / 5 + 32;
var message = convertTemp+'\xB0C is ' + convertToF + ' \xB0F.';
console.log(message);

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

// Change the inputs below to test your code
convertToF(30);
convertToF(-30);
convertToF(0);
convertToF(20);
convertToF(10);
convertToF(-10);

Gurpreet SIngh
@Gurpreet3131
Jun 15 2017 04:19
<p></p> i have this html tag. And i want to put a text from textfile into this tag, how to do this?
NSS534
@NSS534
Jun 15 2017 04:21

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
var convertTemp = celsius;
var convertToF = convertTemp * 9 / 5 + 32;
var message = convertTemp+'\xB0C is ' + convertToF + ' \xB0F.';
console.log(message);

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

// Change the inputs below to test your code
convertToF(30);
convertToF(-30);
convertToF(0);
convertToF(20);
convertToF(10);
convertToF(-10);

Kevin Holmes
@codersc
Jun 15 2017 04:21
help code formatting
Markus Ivancsics
@ivancsicsmarkus
Jun 15 2017 04:21
@codersc Hello, what exactly?
Kevin Holmes
@codersc
Jun 15 2017 04:22
im trying to get the bot to post info on code formatting so @NSS534's code is redable
@ivancsicsmarkus do you know how to do that?
Markus Ivancsics
@ivancsicsmarkus
Jun 15 2017 04:23
@NSS534 @codersc '''
CamperBot
@camperbot
Jun 15 2017 04:23
:bulb: to format code use backticks!  more info
Markus Ivancsics
@ivancsicsmarkus
Jun 15 2017 04:23
@codersc Put three apostrofes! :)
Kevin Holmes
@codersc
Jun 15 2017 04:23
thanks @ivancsicsmarkus
CamperBot
@camperbot
Jun 15 2017 04:23
codersc sends brownie points to @ivancsicsmarkus :sparkles: :thumbsup: :sparkles:
Kevin Holmes
@codersc
Jun 15 2017 04:24
function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
var convertTemp = celsius;
var convertToF = convertTemp * 9 / 5 + 32;
var message = convertTemp+'\xB0C is ' + convertToF + ' \xB0F.';
console.log(message);

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

// Change the inputs below to test your code
convertToF(30);
convertToF(-30);
convertToF(0);
convertToF(20);
convertToF(10);
convertToF(-10);
Austin Butler
@theaustin
Jun 15 2017 04:24
Why is it not returning Yes for this? The only challenges not fufilled are testLogicalAnd(30) returning Yes and testLogicalAnd(25) returning Yes. js
Oops
if (val == 50 && val >= 25) {
  return "Yes";
}
Not sure how to format code correctly
@abohannon
Jun 15 2017 04:25
Can anyone help me? How do I access the value of as property using obj.hasOwnProperty?
Austin Butler
@theaustin
Jun 15 2017 04:26
Oh I figured it out, used wrong operator
Kevin Holmes
@codersc
Jun 15 2017 04:26
@NSS534 you declared fahrenheit but never assigned a value so by default it's value is undefined
OldmanVimes
@OldmanVimes
Jun 15 2017 04:26
I need help with the switch statements
Anyone there?
Who will help me without laughing?

function caseInSwitch(val) {
// Only change code below this line

switch (val){
case 1: console.log("alpha") ; break;
case 2: console.log("beta"); break;
case 3: console.log("gamma"); break;
case 4: console.log("theta"); break;
}
// Only change code above this line
}

Kevin Holmes
@codersc
Jun 15 2017 04:29
var obj = {
foo: 'bar'
};

obj.hasOwnProperty('foo') //returns true
@abohannon
Christopher McCormack
@cmccormack
Jun 15 2017 04:29
@OldmanVimes you're logging to console instead of storing the value in answer
@abohannon
Jun 15 2017 04:29
is there anyway to access 'bar'
mackyking
@mackyking
Jun 15 2017 04:29
@codersc How to send like black background code stuff?
@abohannon
Jun 15 2017 04:29
@codersc
OldmanVimes
@OldmanVimes
Jun 15 2017 04:29
@khaduch Thanks a lot. I appreciate you taking time out to explain . Thank you once again.
CamperBot
@camperbot
Jun 15 2017 04:29
oldmanvimes sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
Christopher McCormack
@cmccormack
Jun 15 2017 04:29

@mackyking


Code goes here, backticks go on their own line. Previous posts can be edited. control + shift + m for detailed Markdown Help.


mackyking
@mackyking
Jun 15 2017 04:29
Markus Ivancsics
@ivancsicsmarkus
Jun 15 2017 04:31
@mackyking This is it. :D
OldmanVimes
@OldmanVimes
Jun 15 2017 04:31
@cmccormack I tried setting val="alpha", didn't work
sandeepdhobi
@sandeepdhobi
Jun 15 2017 04:31
mackyking
@mackyking
Jun 15 2017 04:31
Thanks @cmccormack
CamperBot
@camperbot
Jun 15 2017 04:31
mackyking sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
Markus Ivancsics
@ivancsicsmarkus
Jun 15 2017 04:31
@OldmanVimes You should not log it, you should change the variable answer.
Christopher McCormack
@cmccormack
Jun 15 2017 04:31
@OldmanVimes val is your function parameter that you want to use in your switch statement, your cases will evaluate against val. You want to assign a response to answer, not val
Kevin Holmes
@codersc
Jun 15 2017 04:31
@abohannon console.log(obj.foo) // returns 'bar' to console
Markus Ivancsics
@ivancsicsmarkus
Jun 15 2017 04:32

@sandeepdhobi not contacts[i].prop!
It is:

contacts[i][prop]

because prop is a variable.

@ivancsicsmarkus If you type: contacts[i].prop it will look for a property called "prop".
sandeepdhobi
@sandeepdhobi
Jun 15 2017 04:34
thanks @ivancsicsmarkus
CamperBot
@camperbot
Jun 15 2017 04:34
sandeepdhobi sends brownie points to @ivancsicsmarkus :sparkles: :thumbsup: :sparkles:
OldmanVimes
@OldmanVimes
Jun 15 2017 04:34
@cmccormack thanks lot.
CamperBot
@camperbot
Jun 15 2017 04:34
oldmanvimes sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
NSS534
@NSS534
Jun 15 2017 04:40

function convertToF(celsius) {
var fahrenheit=45;
// Only change code below this line
var convertTemp = celsius;
var convertToF = convertTemp * 9 / 5 + 32;
var message = convertTemp+'\xB0C is ' + convertToF + ' \xB0F.';
console.log(message);

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

// Change the inputs below to test your code
convertToF(30);
convertToF(-30);
convertToF(0);
convertToF(20);
convertToF(10);
convertToF(-10);

@abohannon
Jun 15 2017 04:40
can i use Object.keys to return the value of a key in an object?
Kevin Holmes
@codersc
Jun 15 2017 04:41
you could technically, but object.keys returns an array of keys i think @abohannon
so you would have to loop through the keys to find the one you want
@abohannon
Jun 15 2017 04:42
so if there is only one key and I need to access it's value in order to compare to another array
im forgetting the syntax i think and I cant seem to find it in the documentation
Kevin Holmes
@codersc
Jun 15 2017 04:43
do you know the name of the key you need?
@abohannon
@abohannon
Jun 15 2017 04:44
@codersc yes, but I can't rely on it (the variable might change and thus the object/array as well)
I'm on the shakespeare challenge and the key is Last and the value is Capulet. I can access Last, but I need to be able to evaluate Capulet.
eyesore-
@eyesore-
Jun 15 2017 04:45
If the object only has one key than Object.keys(obj)[0] would give you the key.
Kevin Holmes
@codersc
Jun 15 2017 04:46
in that case i would try to access it only with bracket notation like var obj = { 'foo': 'bar' }; var keyName = 'foo'; obj[keyName] // 'bar'
@abohannon
var obj = {
'foo': 'bar',
'string with a space': 'value'
};

console.log(obj.foo) // works

console.log(obj['foo']) // works

console.log(obj['string with a space']) //works

console.log(obj.string with a space) //error
@abohannon this gives you an idea of why sometimes you need bracket notation to access object key value pairs
mackyking
@mackyking
Jun 15 2017 04:51
Who used bitcoin here?
@abohannon
Jun 15 2017 04:51
hmm i don't think that will work for me in this case. I have to avoid using the actual key name. I can use the key, but not the name because the key name will change. So i need to identify the key, then identify it's value. I could be using the wrong words to describe all of this so I apologize if it's confusing
like i could do (obj)[0]
Kevin Holmes
@codersc
Jun 15 2017 04:52
ill take a look at the challenge
@abohannon
Jun 15 2017 04:53
eyesore-
@eyesore-
Jun 15 2017 04:53
@abohannon Show what you have so far.
@abohannon
Jun 15 2017 04:54
@eyesore- it's not much.

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

for ( var i = 0; i < collection.length; i++ ){
console.log(collection[i]);

}

console.log(collection[1].hasOwnProperty("last"));

console.log(Object.keys(source));

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

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
im doing it in repl.it so the console logs are just testing things out.
a friend of mine showed me a solution earlier and he used double brackets to access the value
but now I cant recall how he did it
@abohannon
Jun 15 2017 05:00
Ok now I have this
  for ( var i = 0; i < collection.length; i++ ){
console.log(collection[i].hasOwnProperty(Object.keys(source)));

}
Kevin Holmes
@codersc
Jun 15 2017 05:00
i would the first step is write up some code that half works. in other words, try write a function that will return all the objects that have they your looking for, then you'll be half way and the answer will come to you i think @abohannon
@abohannon
Jun 15 2017 05:00
which returns true for each
Kevin Holmes
@codersc
Jun 15 2017 05:00
that have the key your looking for*
@abohannon
Jun 15 2017 05:00
ok I think i did that with the above code
now that the loops is saying "yes, all these items have the key in them"
now I need to see "does the value match?" and accessing the value is where I'm running into a roadblock.
eyesore-
@eyesore-
Jun 15 2017 05:06
Let me go through it real quick and I can walk you through the problem.
HappyRedditor59
@HappyRedditor59
Jun 15 2017 05:07
hello!! can anyone please help me with the Find the Longest Word in a String challenge? my code displays TypeError: Cannot read property 'length' of undefined. this is my code:
function findLongestWord(str) {

var separator = ' ';
var longestWord = 0;
var stringArray = str.split(' ');
for (var i = 0; i <= stringArray.length; i++){
longestWord = stringArray[i].length;
if (stringArray[i].length > longestWord)
longestWord = stringArray[i].length;
}
return longestWord;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Moisés Man
@moigithub
Jun 15 2017 05:11
arrays are 0 based index... soo if u have [1,2,3] first element is on 0 index
last element is on 2 index @HappyRedditor59
.length return 3 (on this example).. soo check ur loop conditional again
mackyking
@mackyking
Jun 15 2017 05:11
Who can help to fix the exact syntax?
eyesore-
@eyesore-
Jun 15 2017 05:12
@abohannon Did you change your code at all?
mackyking
@mackyking
Jun 15 2017 05:12
Help me fix the exact syntax please...
@abohannon
Jun 15 2017 05:12
@eyesore- i got a bit further. This is what I have now:

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

for ( var i = 0; i < collection.length; i++ ){
console.log(collection[i].hasOwnProperty(Object.keys(source)));

}

console.log(collection[1].hasOwnProperty("last"));

console.log(Object.keys(source));

console.log(collection[2]);

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

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
eyesore-
@eyesore-
Jun 15 2017 05:13
@abohannon What is your plan of attack? Looping through collection and pushing to arr?
@abohannon
Jun 15 2017 05:14
Yep.
i feel like i should be able to compare the key and value and if both match, return true and push to arr
eyesore-
@eyesore-
Jun 15 2017 05:14
@abohannon If you do that it is going to take a couple of nested for loops which can be confusing. Have you thought about doing it with filter?
@abohannon
Jun 15 2017 05:14
in this case it would be pusing collection[2]
eyesore-
@eyesore-
Jun 15 2017 05:15
@abohannon That could work if the source object always had one key, but it doesn't
@abohannon
Jun 15 2017 05:15
I thought about it but haven't tried it yet
mackyking
@mackyking
Jun 15 2017 05:15

function nextInLine(arr, item) {

arr.push(item);
arr.shift(item);
return arr[0];

// Change this line
}

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

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


@abohannon
Jun 15 2017 05:15
i wanted to mske sure i tried using the methods FCC provided
i can look into filter and see what I come up with
eyesore-
@eyesore-
Jun 15 2017 05:16
@abohannon i'm downto do it with all for loops though and get for loop crazy.
@abohannon
Jun 15 2017 05:16
@eyesore- haha i suck at loops so i guess it will be practice fo rme
eyesore-
@eyesore-
Jun 15 2017 05:16
Wanna jump in a private chat?
@abohannon
Jun 15 2017 05:16
sure that'd be great
mackyking
@mackyking
Jun 15 2017 05:16
function nextInLine(arr, item) { // Your code here arr.push(item); arr.shift(item); return arr[0]; // Change this line } // Test Setup var testArr = [1,2,3,4,5]; // Display Code console.log("Before: " + JSON.stringify(testArr)); console.log(nextInLine(testArr, 6)); // Modify this line to test console.log("After: " + JSON.stringify(testArr));
Kevin Holmes
@codersc
Jun 15 2017 05:18
function nextInLine(arr, item) { // Your code here arr.push(item); arr.shift(item); return arr[0]; // Change this line } // Test Setup var testArr = [1,2,3,4,5]; // Display Code console.log("Before: " + JSON.stringify(testArr)); console.log(nextInLine(testArr, 6)); // Modify this line to test console.log("After: " + JSON.stringify(testArr));
function nextInLine(arr, item) {
arr.push(item);
arr.shift(item);
return arr[0];
// Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
@mackyking hold on im takina look at the challenge
whats the name of the challenge @mackyking
@mackyking do you know how to add an item to an array?
mackyking
@mackyking
Jun 15 2017 05:25
Kevin Holmes
@codersc
Jun 15 2017 05:29
@mackyking
Ogundele Olumide
@Lumexralph
Jun 15 2017 05:29
@mackyking return arr.shift(); // the first element in arr
Kevin Holmes
@codersc
Jun 15 2017 05:29
var arr = [1, 2, 3]

arr.push(4) // arr now looks like [1, 2, 3, 4]

var firstItem = arr.shift() //firstItem now equals 1 and arr looks like [2, 3, 4]

arr[0] // equals 2
read the comments in the code i posteed. can you see what you're doing wrong
?
Curtis
@CurtisJCamp
Jun 15 2017 05:38
Hey everybody, can somebody help me with "WordBlanks" challenge? I dont even understand what they are asking for.
Aaron Bell
@awb715
Jun 15 2017 05:39
anyone know how to use passportjs?
Mudit
@muditagr
Jun 15 2017 05:40
@codersc whats your question? you are doing it correct.
Ogundele Olumide
@Lumexralph
Jun 15 2017 05:44
@CurtisJCamp you're to make a phrase or sentence by concatenating all the strings stored in the 4 parameters of your function and remember to separate them with spaces " "
Cathy
@cathypchui
Jun 15 2017 05:45
@CurtisJCamp think about how you would make a sentence structure with different word types (adverb, verb, etc). If you want to log a sentence with one blank, function oneBlank(noun) { var result = ""; result = "I want to fill in my blank with a noun, " + noun; return result; } oneBlank(apple); //you'd get "I want to fill in my blank with a noun, apple"
Same process, but with sentence structure (e.g. adverb before verb) and more blanks in mind.
sorry, forgot some semicolons there, but hopefully that makes sense (Edit- fixed)
mackyking
@mackyking
Jun 15 2017 06:03
@Lumexralph Thanks a lot...
CamperBot
@camperbot
Jun 15 2017 06:03
mackyking sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1936 | @lumexralph |http://www.freecodecamp.com/lumexralph
mackyking
@mackyking
Jun 15 2017 06:03
@codersc A very much thanks to you...
CamperBot
@camperbot
Jun 15 2017 06:03
mackyking sends brownie points to @codersc :sparkles: :thumbsup: :sparkles:
mackyking
@mackyking
Jun 15 2017 06:04
I already got it guys... Thanks to all suppprt guys...
HappyRedditor59
@HappyRedditor59
Jun 15 2017 06:07
can someone pls help me w/ my code? i'm on the challenge Title Case a Sentence and i get the error of TypeError: Cannot assign to read only property '0' of string 'i'm'. this is my code:
function titleCase(str) {

var strLowerCase = str.toLowerCase().split(' ');

for (var i = 0; i < strLowerCase.length; i++){
strLowerCase[i][0] = strLowerCase[i][0].toUpperCase();
}

strLowerCase = strLowerCase.join(' ');
return strLowerCase;

}

titleCase("I'm a little tea pot");
Sina
@Sinamindev
Jun 15 2017 06:11
How can I convert every parameter passed to a function into array, except the first element?
The first element is an array, and the rest are integers. I want to make an array out of all those integers
Jun 15 2017 06:12
need help with Golf Code
is this code correct? (this is not the full code btw)
if (strokes=1){
return "Hole-in-one!";
}
else if (strokes <= par-2){
return "Eagle";
}
anyone here?
Christopher McCormack
@cmccormack
Jun 15 2017 06:14
@Adrifajar = is assignment, you need to use == or === to compare
Jun 15 2017 06:16
oh, i see. thanks
so in jave script just one "=" don't mean much?
Christopher McCormack
@cmccormack
Jun 15 2017 06:18
@Adrifajar just like most other languages, it's an assignment operator
@Sinamindev
> function arrayFrom(){ return Array.from(arguments).slice(1) }
> arrayFrom([1,2,3], 4, 5, 6)
[ 4, 5, 6 ]
pursuitgit
@pursuitgit
Jun 15 2017 06:27
@HappyRedditor59 you're missing a for loop in your code, you specify strLowerCase[i][0] however you don't have two arrays currently.
@HappyRedditor59 you need to split each element in your array into another array
@HappyRedditor59 this needs another for loop inside, I'll leave it to you to think of how to do it
for (var i = 0; i < strLowerCase.length; i++){
strLowerCase[i][0] = strLowerCase[i][0].toUpperCase();
}
Michael Schmidt
@lafisrap
Jun 15 2017 06:32
@HappyRedditor59 Nice idea. The problem is, that you can't change single characters in a string. Just change one line, and it will work.
strLowerCase[i] = strLowerCase[i][0].toUpperCase() + strLowerCase[i].slice(1);
Pieter Stokkink
@forkerino
Jun 15 2017 06:38
@pursuitgit definitely no need for splitting twice. You can overwrite the words in the array
Kevin Holmes
@codersc
Jun 15 2017 06:39
@Sinamindev r u working on a challenge? if so, which one?
pursuitgit
@pursuitgit
Jun 15 2017 06:40
@forkerino could you provide an example of this? I did the challenge early on today based on stuff previously learnt @ freecodecamp, I saw the slice thing in lafisrap's code but I don't think we've been introduced that in freecodecamp :O
Pieter Stokkink
@forkerino
Jun 15 2017 06:42
@pursuitgit I'm not exactly sure where you are introduced to .slice, but I think it is prior to this exercise.
It is a lot cleaner to use it this way
Michael Schmidt
@lafisrap
Jun 15 2017 06:44
@pursuitgit You could also use .substr(1) if you prefer.
Pieter Stokkink
@forkerino
Jun 15 2017 06:46
@pursuitgit it might be that it only comes at Confirm the Ending, but I only briefly looked through the map.
Andrew
@uandrew
Jun 15 2017 06:46

Hi to all! I am stuck with ES6: Write Higher Order Arrow Functions challange

"strict mode";
const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];
// change code below this line
var squaredIntegers = realNumberArray.map((filter) => realNumberArray*realNumberArray );
// change code above this line
console.log(squaredIntegers);

I can't use if statements, so how can I exclude all non-integer numbers from the array in calculations below?

Mudit
@muditagr
Jun 15 2017 06:47

var count = 0;

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

// Note: Only the last will display
cc(2); cc(3); cc(7);cc('K'); cc('A');
https://www.freecodecamp.com/challenges/counting-cards
Pieter Stokkink
@forkerino
Jun 15 2017 06:47
@uandrew use a .filter and a .map consecutively (chain the methods)
@uandrew or use .reduce
Andrew
@uandrew
Jun 15 2017 06:48
@forkerino SHould have read more about these methods. Hope I'll figure it out, thanks for help)
CamperBot
@camperbot
Jun 15 2017 06:48
uandrew sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2620 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jun 15 2017 06:49
@muditagr those cases will only evaluate the last one (that's how comma's work in JS). You have to specify each one:
case 2:
case 3:
etc.
@uandrew so something like: realNumberArray.filter(...).map(...) Fill in the ....
@muditagr the last if / else is also incorrect. You have to compare count to something there.
@muditagr and your cases need a break after, otherwise all code after inside the switch will also be run.
Michael Schmidt
@lafisrap
Jun 15 2017 06:52
@HappyRedditor59 You solution inspired me to a more modern approach (my first one was much mor ecomplicated then yours ;-))
function titleCase(str) {

return str
.split(' ')
.map((s) => s[0].toUpperCase() + s.substr(1).toLowerCase())
.join(' ');
}

titleCase("I'm a little tea pot");
Pieter Stokkink
@forkerino
Jun 15 2017 06:53
@lafisrap since you're using ES6 anyway, you might as well [...str]
oh wait, that won't work
sorry
:joy:
splits by every character
Michael Schmidt
@lafisrap
Jun 15 2017 06:55
@forkerino But if you have an idea to make it more beautiful, tell me ...
@forkerino You need split, yes.
Pieter Stokkink
@forkerino
Jun 15 2017 06:56
@lafisrap this is fine, actually. Another way is using a RegExp, but that's not the easiest to read, because there's a special case to think of.
Michael Schmidt
@lafisrap
Jun 15 2017 06:57
@forkerino RegExp are fantastic! But a little complicated here ;-)
Pieter Stokkink
@forkerino
Jun 15 2017 06:58
@lafisrap there is one for finding word boundaries, but the problem is that it considers the single quote in I'm to be a word boundary.
Michael Schmidt
@lafisrap
Jun 15 2017 06:59
@forkerino I don't like the word bounderies because they don't find Umlauts (äöü), so it's not suitable for German.
Pieter Stokkink
@forkerino
Jun 15 2017 06:59
really? Didn't know that.
Michael Schmidt
@lafisrap
Jun 15 2017 06:59
Yeah.
Pieter Stokkink
@forkerino
Jun 15 2017 07:00
We in Holland rarely have an Umlaut at the beginning. Only one I can think of is words borrowed from German @lafisrap
Michael Schmidt
@lafisrap
Jun 15 2017 07:01
@forkerino Doesn't matter where they are, they are a word boundary.
@forkerino I had my fights ...
Pieter Stokkink
@forkerino
Jun 15 2017 07:01
aah, ok
I tried, definitely weird behaviour.
"äm a little teäpot".replace(/\b\w/g, 'bleep')
"äbleep bleep bleepittle bleepeäbleepot"
Sina
@Sinamindev
Jun 15 2017 07:03
@cmccormack Thanks that helped
CamperBot
@camperbot
Jun 15 2017 07:03
sinamindev sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
Michael Schmidt
@lafisrap
Jun 15 2017 07:04
@forkerino Yes. That's weird.
Sina
@Sinamindev
Jun 15 2017 07:04
@codersc Im working on 252 Seek and Destroy. I figured out how my problem from earlier, but I'm having trouble with filter() and how I can remove elements from the first array by comparing each element to all elements of the second array
Pieter Stokkink
@forkerino
Jun 15 2017 07:05
Mudit
@muditagr
Jun 15 2017 07:08
@forkerino
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 = count;
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
}

// Note: Only the last will display
cc(2); cc(3); cc(7);cc('K'); cc('A');
Pieter Stokkink
@forkerino
Jun 15 2017 07:08
@muditagr does that work?
Kevin Holmes
@codersc
Jun 15 2017 07:08
@Sinamindev every function has access the arguments object which contains all the paramters passed to the function. that might be helpful to you
Mudit
@muditagr
Jun 15 2017 07:09
@forkerino yes that works now.Thanks for the help. Also, i was comparing if/else the other way . silly me.
CamperBot
@camperbot
Jun 15 2017 07:09
muditagr sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2621 | @forkerino |http://www.freecodecamp.com/forkerino
shedlerman
@shedlerman
Jun 15 2017 07:09

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

{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
];

what wrong?
Pieter Stokkink
@forkerino
Jun 15 2017 07:10
@muditagr :+1: well done. One thing to note: case 7 -9 don't do anything, so you might as well remove them.
@shedlerman elements in arrays are separated by ... ?
Gary Fitzwater
@garyfalkland
Jun 15 2017 07:10
function testGreaterOrEqual(val) {
if (val >= 25) {  // Change this line
return "20 or Over";
}

if (val >= 20) {  // Change this line
return "10 or Over";
}

return "9 or Under";
}

// Change this value to test
testGreaterOrEqual(10);
I dont get how this isnt correct?
Pieter Stokkink
@forkerino
Jun 15 2017 07:11
btw very original to copy the code from the first record. Most people just make up their own... :laughing: @shedlerman
@garyfalkland how does val >= 25 result in 20 or Over? isn't 21 twenty or over?
Wisnu Wardha
@WardhaCS
Jun 15 2017 07:12
var Bike = function() {

// Only change code below this line.
this.getGear=function(change){
return change;
};
};

var myBike = new Bike(4);
X)myBike.getGear() should return 4 after calling myBike.setGear(4).
Sina
@Sinamindev
Jun 15 2017 07:12
@forkerino @codersc
Sorry for the messy code. I feel like I was closer to the solution before, but i've gotten further away ever since
function destroyer(arr) {
// Remove all the values

var args = Array.from(arguments);
var destroy = args.slice(1);
var seek = args[0];

var removedArray = [];
removedArray = seek.filter(function(newArray){
for(var i = 0; i < destroy.length; ++i){
if(seek != destroy[i])
return seek[i];
}
});
Michael Schmidt
@lafisrap
Jun 15 2017 07:13
@garyfalkland val >= 20 and val >=10 would be right
Mudit
@muditagr
Jun 15 2017 07:14
@forkerino
Yes , Thanks . did that earlier , just to be sure with correct output i had put it again. Also, how does multiple call to function work here in a single line and it returns value only from only last call ? is calling them multiple times in single line and multiple times in multiple lines different here?
CamperBot
@camperbot
Jun 15 2017 07:14
muditagr sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: muditagr already gave forkerino points
Pieter Stokkink
@forkerino
Jun 15 2017 07:14
@muditagr it returns a value each time, but the FCC console only shows the last one.
Gary Fitzwater
@garyfalkland
Jun 15 2017 07:14
The exercise states that you fill in so that the return staements make sense, so is it wanting me so that they return as true?
Pieter Stokkink
@forkerino
Jun 15 2017 07:15
putting them on multiple lines or single line has the same effect. @muditagr
shedlerman
@shedlerman
Jun 15 2017 07:15

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

,

"artist1": "Tilly Joel",
"title2": "Miano Man",
"release_year2": 1973,
"formats2": [
"CS",
"8T",
"LP" ],
"golds": true

}

];

Mudit
@muditagr
Jun 15 2017 07:16
@forkerino oh great, Thanks. clears my doubt.
CamperBot
@camperbot
Jun 15 2017 07:16
muditagr sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: muditagr already gave forkerino points
Pieter Stokkink
@forkerino
Jun 15 2017 07:16
@Sinamindev the .filter callback's first argument is the current element of the array you are inspecting, you can use that to compare to the things in your 'destroy' array. A for loop can work, but you can also use .indexOf. Make sure to return true if the value should be kept and false if not.
@Sinamindev also you need to return something from your function (I guess you may have done that below the code you posted).
@shedlerman The second album now misses an opening {
Michael Schmidt
@lafisrap
Jun 15 2017 07:17
@Sinamindev You should use newArray instead of seek
Pieter Stokkink
@forkerino
Jun 15 2017 07:18
^although newArray is badly named, as the parameter represents an element, not the array
Sina
@Sinamindev
Jun 15 2017 07:23

Thanks @forkerino and @lafisrap
I managed to get it working. I had been thinking filter returns the element you want to keep, rather than true or false. This is what I have now:

function destroyer(arr) {
// Remove all the values

var args = Array.from(arguments);
var destroy = args.slice(1);
var seek = args[0];

var removedArray = [];
removedArray = seek.filter(function(newArray){
var keep = true;
for(var i = 0; i < destroy.length; ++i){
if(newArray == destroy[i])
keep = false;
}
return keep;
});

return removedArray;
}

Are there any improvements I could make to this?

CamperBot
@camperbot
Jun 15 2017 07:23
sinamindev sends brownie points to @forkerino and @lafisrap :sparkles: :thumbsup: :sparkles:
:star2: 2622 | @forkerino |http://www.freecodecamp.com/forkerino
sarthakcoder
@sarthakcoder
Jun 15 2017 07:27

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

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

// Change the inputs below to test your code
convertToF(30);
its not running??

Manish Giri
@Manish-Giri
Jun 15 2017 07:29
@sarthakcoder use the * operator
Sina
@Sinamindev
Jun 15 2017 07:29

@sarthakcoder

fahrenheit = (9/5) celsius + 32 ;

How would you like (9/5) interact with celsius?

Pieter Stokkink
@forkerino
Jun 15 2017 07:29
@Sinamindev good start. You could replace the loop inside your filter with an .indexOf , as this finds a value in an array (which is what you are doing).
sarthakcoder
@sarthakcoder
Jun 15 2017 07:30
@Manish-Giri @Sinamindev thanks
CamperBot
@camperbot
Jun 15 2017 07:30
sarthakcoder sends brownie points to @manish-giri and @sinamindev :sparkles: :thumbsup: :sparkles:
:star2: 5984 | @manish-giri |http://www.freecodecamp.com/manish-giri
Shashank Shekhar
@ashwamegh
Jun 15 2017 07:34
How to approach this problem https://www.freecodecamp.com/challenges/exact-change , my code fails some test ...
currencies=[
["PENNY",0.01],
["NICKEL", 0.05],
["DIME"  , 0.1],
["QUARTER", 0.25],
["ONE", 1],
["FIVE", 5],
["TEN" , 10],
["TWENTY" , 20],
["ONE HUNDRED", 100]
];
currencies = currencies.reverse();

function checkCashRegister(price, cashPay, cid) {

// CHANGE TO BE RETURNED
let change = cashPay - price, cash_in_drawer = 0, change_returned = [];

// CASH AVAILABLE IN DRAWER
let cash_in_drawer_arr = cid.map((arr) => cash_in_drawer + arr[1]);
cash_in_drawer = parseInt(cash_in_drawer_arr.reduce((accum, num) => accum+num)).toFixed(2);
console.log(cash_in_drawer);
if ( cash_in_drawer > change){
currencies.map((cunits) => {
if (change !== 0 && change%cunits[1] === 0){
change_returned.push([cunits[0],change]);
}
else if(change !== 0 && change%cunits[1] !== 0 && cunits[1]<change){
change_returned.push([cunits[0],change/cunits[1]]);
change = (change % cunits[1]).toFixed(2);
console.log(change);
}
});
console.log(change_returned);
return change_returned;
}

else if( cash_in_drawer < change){
return "Insufficient Funds";
}
else if( cash_in_drawer === change){
return "Closed";
}
console.log(cash_in_drawer);
return change;
}

checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);
Sina
@Sinamindev
Jun 15 2017 07:44
@forkerino here's with using .indexOf()
  var removedArray = seek.filter(function(value){
if(destroy.indexOf(value) !== -1)
return false;
else
return true;
});
sarthakcoder
@sarthakcoder
Jun 15 2017 07:47

myStr should have encoded text with the proper escape sequences and no spacing??

var myStr = "FirstLine'\n'\SecondLine\'\r'ThirdLine"; // Change this line

Mohak Chaturvedi
@lucky73
Jun 15 2017 07:49
i am unable to acces glove box dont understannd why

// 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"].glovebox; // Change this line

Pieter Stokkink
@forkerino
Jun 15 2017 07:50
@lucky73 there's a space in glove box, so you cannot use dot notation for it.
@Sinamindev if you reverse the condition you can return immediately: return destroy.indexOf(value) === -1
Mohak Chaturvedi
@lucky73
Jun 15 2017 07:51
@forkerino glove.box like this
Pieter Stokkink
@forkerino
Jun 15 2017 07:51
@lucky73 no, use brackets around the whole thing.
Markus Kiili
@Masd925
Jun 15 2017 07:53
@lucky73 The string "glove box" has a space in it, so it cannot be a valid JS identifier name and cannot be used as a key when dot notation is used. Bracket notation can be used with arbitrary strings.
Pieter Stokkink
@forkerino
Jun 15 2017 07:53
@shashank7200 haven't looked at your code in depth, but I think you are getting floating point inaccuracies. One solution is to multiply everything by 100 before doing calculations and divide again before returning. Another is to round to 2 decimals with toFixed and convert it back to a number.
Mohak Chaturvedi
@lucky73
Jun 15 2017 07:53
@forkerino var gloveBoxContents = myStorage.car["inside"]["glovebox"];
Pieter Stokkink
@forkerino
Jun 15 2017 07:54
@lucky73 that space has to be there in "glove box"
Shashank Shekhar
@ashwamegh
Jun 15 2017 07:54
I am trying @forkerino
Mohak Chaturvedi
@lucky73
Jun 15 2017 07:55
@Masd925 @forkerino thank you
CamperBot
@camperbot
Jun 15 2017 07:55
lucky73 sends brownie points to @masd925 and @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2623 | @forkerino |http://www.freecodecamp.com/forkerino
:star2: 4268 | @masd925 |http://www.freecodecamp.com/masd925
Wisnu Wardha
@WardhaCS
Jun 15 2017 07:56
var array = [1,2,3,4,5,6,7];
var newArray = [];

// Only change code below this line.

newArray = array.reverse(function(a,b){
return a-b;
});
X)You should use the reverse method.
Manish Giri
@Manish-Giri
Jun 15 2017 07:56
@WardhaCS just .reverse()
Mikita Shrestha
@mikita167
Jun 15 2017 07:57

// Example
var changed = 0;

function change(num) {
return (num + 5) / 3;
}

changed = change(10);

// Setup
var processed = 0;

function processArg(num) {
return (num + 3) / 5;
}

// Only change code below this line

processed = processArg (7);

Call the processArg function with an argument of 7 and assign its return value to the variable processed.
I am very confused about what to so next
Pieter Stokkink
@forkerino
Jun 15 2017 07:59
@sarthakcoder there should be no quotes in your string.
Manish Giri
@Manish-Giri
Jun 15 2017 08:00
@mikita167 processArg (7);
delete the space
@forkerino :wave:
Pieter Stokkink
@forkerino
Jun 15 2017 08:01
@Manish-Giri Hey! what's up?
isn't it like the middle of the night where you are?
#nosleep
Manish Giri
@Manish-Giri
Jun 15 2017 08:02
yeah man like 4 am
Pieter Stokkink
@forkerino
Jun 15 2017 08:02
ok, sweet dreams!
Mikita Shrestha
@mikita167
Jun 15 2017 08:03
@Manish-Giri life saver. Thank you. I was abt to bang my head in the wall ;)
CamperBot
@camperbot
Jun 15 2017 08:03
mikita167 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5985 | @manish-giri |http://www.freecodecamp.com/manish-giri
Aakash Bhusal
@aakashbhusal7
Jun 15 2017 08:05

var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};

// Only change code below this line;

var playerNumber; // Change this Line
var player = testObj;

Use the playerNumber variable to lookup player 16 in testObj using bracket notation.

Manish Giri
@Manish-Giri
Jun 15 2017 08:05
@mikita167 lol, good you didn't!
Pieter Stokkink
@forkerino
Jun 15 2017 08:05
@mikita167 Note that in general it doesn't really matter if there is a space there, the tests are just a bit particular. (It is good practice to just put the parentheses right after the function)
@Manish-Giri Maybe you should stay awake until 6k
:smile:
Manish Giri
@Manish-Giri
Jun 15 2017 08:05
lol
I've been trying to get there since a couple of days, but could only manage 2-3 cookies lately
lol
Pieter Stokkink
@forkerino
Jun 15 2017 08:06
:joy:
ty @Manish-Giri
CamperBot
@camperbot
Jun 15 2017 08:06
forkerino sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5986 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Jun 15 2017 08:06
@aakashbhusal7 the instructions tell you what to do!
lol
Pieter Stokkink
@forkerino
Jun 15 2017 08:06
@aakashbhusal7 put a number in playerNumber and use that variable to look up the value on the testObj
Manish Giri
@Manish-Giri
Jun 15 2017 08:06
ty @forkerino
CamperBot
@camperbot
Jun 15 2017 08:06
manish-giri sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2624 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jun 15 2017 08:06
:+1:
Aakash Bhusal
@aakashbhusal7
Jun 15 2017 08:08
got confused on such tiny thing..anyways thanks
@forkerino :+1:
Wrlgz
@luoganzhi
Jun 15 2017 08:09
someone can help me？
i dont know how to do it
Aakash Bhusal
@aakashbhusal7
Jun 15 2017 08:10
@forkerino :sparkles: :+1: :sparkles:
Pieter Stokkink
@forkerino
Jun 15 2017 08:11
@aakashbhusal7 no problem!
@luoganzhi you can use the arguments object to get all the arguments of the function. Use a filter on the array and remove all values that are equal to the other arguments.
Wrlgz
@luoganzhi
Jun 15 2017 08:13
but there just a arr so i dont know how to filter @forkerino
sarthakcoder
@sarthakcoder
Jun 15 2017 08:13
var myStr = "FirstLine'\n'\SecondLine\'\r'ThirdLine"; // Change this line
not running??
Sina
@Sinamindev
Jun 15 2017 08:13
@forkerino Thats incredible, Thank you!
CamperBot
@camperbot
Jun 15 2017 08:13
sinamindev sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: sinamindev already gave forkerino points
Pieter Stokkink
@forkerino
Jun 15 2017 08:13
@sarthakcoder remove all single quotes from your string
@Sinamindev :+1:
sarthakcoder
@sarthakcoder
Jun 15 2017 08:14
@forkerino got it
Pieter Stokkink
@forkerino
Jun 15 2017 08:15
great
@Sinamindev usually when you have an if else that returns true and false, you can just return the condition (or the inverse of it).
provided nothing else goes on inside
ResoGuy
@Resoguy
Jun 15 2017 08:16
hi guys can someone tell me what's wrong with my code pls?
Pieter Stokkink
@forkerino
Jun 15 2017 08:16
sure
ResoGuy
@Resoguy
Jun 15 2017 08:16
im trying to do 'Return Largest Numbers in Arrays' problem

function largestOfFour(arr) {
// You can do this!
var maxArr = [];
var max = 0;

for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr[i].length; j++) {
max = ((arr[i][j] > max) ? arr[i][j] : max );

}
maxArr.push(max);

}
return maxArr;
}

ops

function largestOfFour(arr) {
// You can do this!
var maxArr = [];
var max = 0;

for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr[i].length; j++) {
max = ((arr[i][j] > max) ? arr[i][j] : max );

}
maxArr.push(max);

}
return maxArr;
}

i cant write code to this chat sorry
:(
Pieter Stokkink
@forkerino
Jun 15 2017 08:17
no problem
what's the issue?
ResoGuy
@Resoguy
Jun 15 2017 08:18
there r 3 test cases as you know the first and 3rd is working but 2nd return [27, 27, ....]
Pieter Stokkink
@forkerino
Jun 15 2017 08:19
@Resoguy sounds like you need to reset max at some point after pushing it
ResoGuy
@Resoguy
Jun 15 2017 08:20
yay did that now passed thx <3
Pieter Stokkink
@forkerino
Jun 15 2017 08:20
@Resoguy btw 0 is not the lowest number (it passes the tests, but what if an array only has negative values? The code would break!). I advice people to use -Infinity instead.
Kamal
@kpbro
Jun 15 2017 08:20
function titleCase(str) {

var lowstr = str.toLowerCase();
var str2arr = lowstr.split(' ');
var newArr = [];

for(var i=0;i<str2arr.length;i++){
var word = str2arr[i].charAt(0).toUpperCase()+str2arr[i].slice(1);
newArr.push(word);
}

var finalString = newArr.join(' ');

return finalString;
}

titleCase("I'm a little tea pot");
I have created this code for capitalizing 1st letter of each word in string. It is working perfectly. Is there any other shorter way of doing this ?
Pieter Stokkink
@forkerino
Jun 15 2017 08:22
@kpbro shortest is to use .map() or a regex (the latter isn't perfect for other languages, but works for the tests).
utkarsh dixit
@ud1996
Jun 15 2017 08:23
hey guys!!!can anyone hep me up with this https://www.freecodecamp.com/challenges/profile-lookup challenge?
Pieter Stokkink
@forkerino
Jun 15 2017 08:24
@ud1996 did you try something?
utkarsh dixit
@ud1996
Jun 15 2017 08:24

function lookUpProfile(firstName, prop){
// Only change code below this line
for(i=0;i<4;i++){
if(contacts[i][firstName]==firstName)
{
if(contacts[i].firstName==prop||contacts[i].lastName==prop||contacts[i].number==prop||contacts[i].likes==prop)
return contacts[i][prop];
else
return "No such property";

     }
else
return "No such contact";
}

// Only change code above this line
}

Kamal
@kpbro
Jun 15 2017 08:25
@forkerino So in .map I create a new array with all 1st letter capitalized.
and join that array
is it right?
Pieter Stokkink
@forkerino
Jun 15 2017 08:26
@ud1996 that second if should be replaced by one where you check if the current contact has the property prop.
@kpbro yes, pretty much what you did in the for loop, but just return it instead of pushing to another array.
@ud1996 prop will be something like "lastName", but the value of the property lastName is not "lastName" (I don't know anyone whose last name is "lastName")
utkarsh dixit
@ud1996
Jun 15 2017 08:28
@forkerino i thinking i am checking the same!!! can you please give me a sample code??
vanagasa
@vanagasa
Jun 15 2017 08:28
Hey can I use 2 var in for loop to change evrytime? for ex for(var i=0;i<...;i++,x--) or smth like that?
Pieter Stokkink
@forkerino
Jun 15 2017 08:29
@ud1996 no, you are checking if the value of firstName is equal to the property name, you compare two different sides of key/value pairs. Use .hasOwnProperty(prop) instead.
utkarsh dixit
@ud1996
Jun 15 2017 08:30
ok @forkerino ....thanx i got that!!!
CamperBot
@camperbot
Jun 15 2017 08:30
ud1996 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2625 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jun 15 2017 08:30
@vanagasa yes, you can even declare two variables in the head of the loop: for (var i=0, x=20; i<x; i++, x--){
Dreijer1337
@Dreijer1337
Jun 15 2017 08:30

Hey guys. I have no idea how to start here. Am I supposed to use the shift and unshift commands or what? function nextInLine(arr, item) {

return arr; // Change this line
}

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

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

I am supposed to do a queue
Pieter Stokkink
@forkerino
Jun 15 2017 08:32
@Dreijer1337 shift is correct, but unshift adds to the beginning, what method adds to the end?
vanagasa
@vanagasa
Jun 15 2017 08:32
@forkerino Oh, Thx
CamperBot
@camperbot
Jun 15 2017 08:32
vanagasa sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2626 | @forkerino |http://www.freecodecamp.com/forkerino
Dreijer1337
@Dreijer1337
Jun 15 2017 08:32
Hmm push or pop I think, looking it up, thanks
Kamal
@kpbro
Jun 15 2017 08:33
function titleCase(str) {

var lowstr = str.toLowerCase();
var str2arr = lowstr.split(' ');

var newArr = str2arr.map(function(word){
return word.charAt(0).toUpperCase + word.slice(1);
});

var final = newArr.join(' ');
return final;
}
@forkerino I tried this.. but not working
ResoGuy
@Resoguy
Jun 15 2017 08:33
how can you send that brownie points to pieter? i'd like to send too:P he is very helpful
Pieter Stokkink
@forkerino
Jun 15 2017 08:34
@Resoguy you say 'thanks' and mention that person with @
:P
ResoGuy
@Resoguy
Jun 15 2017 08:34
oh k thanks @forkerino
CamperBot
@camperbot
Jun 15 2017 08:34
resoguy sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2627 | @forkerino |http://www.freecodecamp.com/forkerino
Dreijer1337
@Dreijer1337
Jun 15 2017 08:34
Thanks @forkerino
CamperBot
@camperbot
Jun 15 2017 08:34
dreijer1337 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2628 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jun 15 2017 08:34
:+1: to you both
@kpbro you're missing () after toUpperCase
but that's a step in the right direction.
Kamal
@kpbro
Jun 15 2017 08:36
@forkerino oh yes.. shiit. how can i for get such important thing.. thanks
CamperBot
@camperbot
Jun 15 2017 08:36
kpbro sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2629 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jun 15 2017 08:36
Try to minimize declaring variables if you use them only once.
@kpbro
Kamal
@kpbro
Jun 15 2017 08:36
@forkerino yes.. i changed it to return newArr.join(' ');
Pieter Stokkink
@forkerino
Jun 15 2017 08:36
that will clean up the code even more
@kpbro you can even chain everything. i.e. the first word inside your function can be 'return'
Kamal
@kpbro
Jun 15 2017 08:38
@forkerino yup.. thanks.. this is working
Marco Galizzi
@Tezenn
Jun 15 2017 08:39
hello, with reduce i can trnaform an array to an object, and after i did some works can i transform back the object to an array? thanks
Kamal
@kpbro
Jun 15 2017 08:39
how can i show here one line code such that it appears different from other text?
Chris Juchtmans
@kjuchtmans
Jun 15 2017 08:39
good morning all coders, you Flower of Youth! :wave:
Pieter Stokkink
@forkerino
Jun 15 2017 08:40
@kpbro use  on either side of the code
Marco Galizzi
@Tezenn
Jun 15 2017 08:40
morning!
Pieter Stokkink
@forkerino
Jun 15 2017 08:40
@kjuchtmans :wave:
Toro
@blessed2016
Jun 15 2017 08:40
Hello
Kamal
@kpbro
Jun 15 2017 08:40
like this
yes.. got it
Chris Juchtmans
@kjuchtmans
Jun 15 2017 08:40
what better way to start the day with fresh coffee & an article on CORS, JSON et XHR :ok_hand:
Toro
@blessed2016
Jun 15 2017 08:41

please can anyone tell me whats wrong with this code. its using objects for Lookup challenge: function phoneticLookup(val) {
var result = "";

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

var value ="";
lookup[value] = result;

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

// Change this value to test
phoneticLookup("alpha");

Pieter Stokkink
@forkerino
Jun 15 2017 08:41
@Tezenn yes you can, but you'd have to probably use Object.keys() to get an array of keys, which you can then .map over to create the array you want
@blessed2016 you have to use the val parameter.
Marco Galizzi
@Tezenn
Jun 15 2017 08:42
@forkerino thanks man
CamperBot
@camperbot
Jun 15 2017 08:42
tezenn sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2630 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jun 15 2017 08:42
@blessed2016 assignment is right to left, so when you assign to result, result should be on the left.
@Tezenn :+1:
Toro
@blessed2016
Jun 15 2017 08:45
@forkerino ok thanks.
CamperBot
@camperbot
Jun 15 2017 08:45
blessed2016 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2631 | @forkerino |http://www.freecodecamp.com/forkerino
Dreijer1337
@Dreijer1337
Jun 15 2017 08:45

What am I doing wrong here? The function does what it was supposed to do I think?

function nextInLine(arr, item) {
var arr = [7,8];
var item = 9;
arr.push(item);
removedNum = arr.shift();

return removedNum; // Change this line
}

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

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

Didun Morodolu
@wombolo
Jun 15 2017 08:46
hello I'm having issues with the topic Returning Boolean Values from Functions
where I have to compare 2 variables to find out which is less than the other
Pieter Stokkink
@forkerino
Jun 15 2017 08:46
@Dreijer1337 don't overwrite arr and item inside your function. Those are the parameters, when the function is called, they are given values
@wombolo what did you try?
Dreijer1337
@Dreijer1337
Jun 15 2017 08:47
@forkerino Ah, I see. Simply changing the names worked :D.
@forkerino Thanks
CamperBot
@camperbot
Jun 15 2017 08:47
dreijer1337 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: dreijer1337 already gave forkerino points
Toro
@blessed2016
Jun 15 2017 08:48
@forkerino : you have to use the val parameter. How do i do this?
Pieter Stokkink
@forkerino
Jun 15 2017 08:49
@blessed2016 val has the name of the key in it, so you can use that to access the right property value in the lookup object.
Didun Morodolu
@wombolo
Jun 15 2017 08:50
@forkerino

function isLess(a, b) {
// Fix this code

return a === b;

}

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

Pieter Stokkink
@forkerino
Jun 15 2017 08:51
@wombolo that code would return true if a is equal to b. You'd have to do something similar but with less than instead of equal to
Toro
@blessed2016
Jun 15 2017 08:52
@forkerino I will check
Jun 15 2017 09:05

Hey guys, I keep returning one here when I should be returning the product of each item in the sub-arrays anyone see whats going on?

I feel like I'm returning the unchanged product variable which of course equals 1 but I'm not sure.

https://www.freecodecamp.com/challenges/nesting-for-loops

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

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Pieter Stokkink
@forkerino
Jun 15 2017 09:06
@zacknovosad your array is named arr, not multiplyAll, the latter is your function name
Jun 15 2017 09:06
oh
my
god
Pieter Stokkink
@forkerino
Jun 15 2017 09:06
lol
Jun 15 2017 09:06
Pahaha. Thank you so much!
vanagasa
@vanagasa
Jun 15 2017 09:08
Hey can how can I store multiple arrays passed by function to a single array?
Toro
@blessed2016
Jun 15 2017 09:08
@forkerino i can't really relate it to this challenge.
Pieter Stokkink
@forkerino
Jun 15 2017 09:09
@blessed2016 lookup is your object, val is your key and you need to store the value in there in result
Didun Morodolu
@wombolo
Jun 15 2017 09:09
@forkerino thanks it works
CamperBot
@camperbot
Jun 15 2017 09:09
wombolo sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2632 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jun 15 2017 09:10
:+1:
Kevin
@kevinwr
Jun 15 2017 09:17
Hey, all. What does it mean to "get" and "set" a value when putting it in a constructor function? I have a private variable in my constructor function, and it wants me to get and set the value of that variable using two methods (one to get and one to set) inside the constructor function,
Pieter Stokkink
@forkerino
Jun 15 2017 09:20
@FlawlessSardine inside your constructor, you have access to the private variables, outside it, you do not. So when you have a private variable and create methods to change that variable or to retrieve it, you hide it from the outside world, which is good practice in many circumstances. 'get' just returns the current value and 'set' sets the value of the private variable.
mihaiIamandi
@mihaiIamandi
Jun 15 2017 09:22
I need some help

unction sumAll(arr) {
var min = Math.min(arr[0],arr[1]);
var max = Math.max(arr[0],arr[1]);
var range = [];
for(var i = min; i<=max.max;i++){
range.push(i);

}

return range.reduce(function(a,b){
return a+b;
});

}

This is my code for Sum All Numbers in A range
Toro
@blessed2016
Jun 15 2017 09:22
@forkerino this is what i have done so far. val = "";
result = lookup[val]; what do i do to allow it check other values.
mihaiIamandi
@mihaiIamandi
Jun 15 2017 09:23
The console say that is a typeError Reduce of empty array with no initial value
Pieter Stokkink
@forkerino
Jun 15 2017 09:23
@blessed2016 don't change val, val already has a value at that point.
@mihaiIamandi i<=max.max doesn't make sense.
mihaiIamandi
@mihaiIamandi
Jun 15 2017 09:24
@forkerino Omg that one is a stupid mistake , Thank you very much
CamperBot
@camperbot
Jun 15 2017 09:24
mihaiiamandi sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2633 | @forkerino |http://www.freecodecamp.com/forkerino
Toro
@blessed2016
Jun 15 2017 09:25
@forkerino ohh ok. thanks!!!!
CamperBot
@camperbot
Jun 15 2017 09:25
blessed2016 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: blessed2016 already gave forkerino points
Romuald Escande
@Romusc
Jun 15 2017 09:26

I have the following behaviour for a button on a lot of my forms. I would like to see if I can refactor it.

$("#submit_button").attr("disabled", "disabled")$("#field_id_1,#field_id_2,#field_id_3").keyup(function() {
if ("#form").valid()) {
$("#submit_button").removeAttr("disabled") } else {$("#submit_button").attr("disabled", "disabled")
}
})

I would like to create a class that allows me to have this behaviour. Is that possible or is my logic flawed?
It seems that we would need at least the form as a variable.

If not by creating a class, how could I refactor this and is this worth refactoring?

Kevin
@kevinwr
Jun 15 2017 09:26
@forkerino ok I figured out what it was wanting. sometimes these instructions make the task way harder than it actually is. haha. Thanks for the help.
CamperBot
@camperbot
Jun 15 2017 09:26
flawlesssardine sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2634 | @forkerino |http://www.freecodecamp.com/forkerino
Aman
@codeyhere
Jun 15 2017 09:27

My code would be false:

function smallestCommons(arr) {
// Sort array from greater to lowest
arr.sort(function(a, b) {
return b - a;
});

// Create new array and add all values from greater to smaller from the
// original array.
var newArr = [];
for (var i = arr[0]; i >= arr[1]; i--) {
newArr.push(i);
}

// Variables needed declared outside the loops.
var quot = 0;
var loop = 1;
var n;

// Run code while n is not the same as the array length.
do {
quot = newArr[0] * loop * newArr[1];
for (n = 2; n < newArr.length; n++) {
if (quot % newArr[n] !== 0) {
break;
}
}

loop++;
} while (n !== newArr.length);

return quot;
}

smallestCommons([1, 13]);

smallestCommons([1,5]);
Tiago Malheiro
@Azzrah
Jun 15 2017 09:29
how can I paste my code here?
@mierz00
Jun 15 2017 09:29
'''
CamperBot
@camperbot
Jun 15 2017 09:29
:bulb: to format code use backticks!  more info
@mierz00
Jun 15 2017 09:29
Pieter Stokkink
@forkerino
Jun 15 2017 09:30
@Romusc that if doesn't look like valid syntax. Seems something is missing.
Tiago Malheiro
@Azzrah
Jun 15 2017 09:32
so I type ''' here and shift enter, thats it?
CamperBot
@camperbot
Jun 15 2017 09:32
:bulb: to format code use backticks!  more info

@lvmin
Jun 15 2017 09:32
hello
Tiago Malheiro
@Azzrah
Jun 15 2017 09:33
nvm I understand it now lol
Kamal
@kpbro
Jun 15 2017 09:33
function largestOfFour(arr) {
// You can do this!
var largest = [];
for(var i=0;i<arr.length;i++){//loop to itereate through main array

var sorted = arr[i].sort(function(a,b){
return b-a;
});//this function sorts sub-array elements in decending order
largest.push(sorted[0]);
}

return largest;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Tiago Malheiro
@Azzrah
Jun 15 2017 09:34
// Setup
function phoneticLookup(val) {
var result = "";

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

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

// Change this value to test
phoneticLookup("charlie");
Pieter Stokkink
@forkerino
Jun 15 2017 09:34
@codeyhere it seems to work, no? Do you get errors?
Tiago Malheiro
@Azzrah
Jun 15 2017 09:34
Pieter Stokkink
@forkerino
Jun 15 2017 09:34
@Azzrah you still have to put the right value in the result variable.
Boris Yordanov
@borisyordanov
Jun 15 2017 09:35
@Azzrah you need a switch case - https://www.w3schools.com/js/js_switch.asp
Pieter Stokkink
@forkerino
Jun 15 2017 09:36
@borisyordanov the exercise is to replace a switch with a lookup object
Tiago Malheiro
@Azzrah
Jun 15 2017 09:36
I can't use switch nor case
Boris Yordanov
@borisyordanov
Jun 15 2017 09:36
@forkerino yep, my bad, sorry @Azzrah
Skaljic
@Skaljic
Jun 15 2017 09:37

Can anyone explain to me what permut() is in this code.

function permAlone(string) {
if (string.length < 2) return string; // This is our break condition

var permutations = []; // This array will hold our permutations

for (var i=0; i<string.length; i++) {
var char = string[i];

// Cause we don't want any duplicates:
if (string.indexOf(char) != i) // if char was used already
continue;           // skip it this time

var remainingString = string.slice(0,i) + string.slice(i+1,string.length); //Note: you can concat Strings via '+' in JS

for (var subPermutation of permut(remainingString))
permutations.push(char + subPermutation);

}
return permutations;

}

permAlone('aab');

Saif Ur Rahman
@saifsmailbox98
Jun 15 2017 09:38
@Skaljic it is a function
Pieter Stokkink
@forkerino
Jun 15 2017 09:38
@Skaljic it looks like a function that returns an array of permutations. I think this code is meant to be recursive, so you can try plugging in permAlone` instead.
Rinor Bivolaku
@RinorNotorious
Jun 15 2017 09:39
@Azzrah before return result you need to do this result = lookup[val]
Saif Ur Rahman
@saifsmailbox98
Jun 15 2017 09:39
Milamanieva
@Milamanieva
Jun 15 2017 09:40
hey guys
Pieter Stokkink
@forkerino
Jun 15 2017 09:40
@Skaljic problem here is that you'll end up with an array of permutations instead of a number
Skaljic
@Skaljic
Jun 15 2017 09:40
Ah cool, tried to google it but didn't find any answers. @saifsmailbox98 and @forkerino Thanks
CamperBot
@camperbot
Jun 15 2017 09:40
skaljic sends brownie points to @saifsmailbox98 and @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2635 | @forkerino |http://www.freecodecamp.com/forkerino
Milamanieva
@Milamanieva
Jun 15 2017 09:40
is it something wrong in this code?
var myArray = [ ["Paul", 35], ["John", 23], ["dog", 3]];
myArray.shift();
myArray.unshift(["Paul", 35]);
Saif Ur Rahman
@saifsmailbox98
Jun 15 2017 09:41
@Milamanieva it looks good to me
Pieter Stokkink
@forkerino
Jun 15 2017 09:41
@Milamanieva why did you change myArray? You added Paul/35 in two places...
Saif Ur Rahman
@saifsmailbox98
Jun 15 2017 09:41
@Milamanieva are you doing a challenge?
Milamanieva
@Milamanieva
Jun 15 2017 09:42
ja.
Add ["Paul",35] to the beginning of the myArray variable using unshift().
that is what they want from me
Kevin
@kevinwr
Jun 15 2017 09:42
@Milamanieva it's fine, but you're removing ["Paul", 35], and then adding it back in at the beginning of the array. It won't change
Saif Ur Rahman
@saifsmailbox98
Jun 15 2017 09:42
@Milamanieva so you only need to use unshift on myArray
Pieter Stokkink
@forkerino
Jun 15 2017 09:43
@Milamanieva that's what you did, but you also added Paul to myArray in the first line of the code. Don't do that.
Milamanieva
@Milamanieva
Jun 15 2017 09:43
so I have to unshift John, 23 instedad?
ahh so I should delete it
Saif Ur Rahman
@saifsmailbox98
Jun 15 2017 09:43
@Milamanieva don't reinitialize the value of myArray
Pieter Stokkink
@forkerino
Jun 15 2017 09:43
yeah, only change the one line.
Saif Ur Rahman
@saifsmailbox98
Jun 15 2017 09:43
line 1
Kevin
@kevinwr
Jun 15 2017 09:43
naw, just take it out from the array at the start
Tiago Malheiro
@Azzrah
Jun 15 2017 09:44
@RinorNotorious I got it, thanks guys
CamperBot
@camperbot
Jun 15 2017 09:44
azzrah sends brownie points to @rinornotorious :sparkles: :thumbsup: :sparkles: