17th
May 2016
Christian Todd
@chrstntdd
May 17 2016 00:00
is anyone available to help me through the Caesars Cipher bonfire?
CamperBot
@camperbot
May 17 2016 00:00
type bonfire name to get some info on that bonfire. And check HelpBonfires chatroom
Christian Todd
@chrstntdd
May 17 2016 00:01

This is what I have so far


function rot13(str) { // LBH QVQ VG!
var strArr = str.split("");
var numArr = [];
for (var i = 0; i < strArr.length; i++){
numArr = strArr[i].charCodeAt(i);
}

return numArr;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");

allisonletts
@allisonletts
May 17 2016 00:01
help caesars cipher
CamperBot
@camperbot
May 17 2016 00:01

## :point_right: algorithm caesars cipher [wiki]

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :memo:

# :checkered_flag: Problem Explanation:

• You need to write a function, which will take a string encoded with
Caesar cipher as a parameter and decode it.
• The one used here is ROT13 where the value of the letter is
shifted by 13 places.
e.g. 'A' β 'N', 'T' β 'G'.
• You have to shift it back 13 positions, such that 'N' β 'A'.
Christian Todd
@chrstntdd
May 17 2016 00:02

function rot13(str) { // LBH QVQ VG!
var strArr = str.split("");
var numArr = [];
for (var i = 0; i < strArr.length; i++){
numArr = strArr[i].charCodeAt(i);
}

return numArr;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Nick
@nickiowaspain
May 17 2016 00:03
This message was deleted
Christian Todd
@chrstntdd
May 17 2016 00:03
So my thinking is to split the string into an array of each character, convert to unicode, do the transformation, then convert back to a string and join the array.
but right now its returning null in the console and I'm just trying to test to see if the method will convert to the unicode.
Nick
@nickiowaspain
May 17 2016 00:06
So I'm on "Selecting from many options with Switch Statements" and this code work however I'm wondering why there are the warning exclamation points that say "unreachable 'break' after 'return.'" on the break lines. Should I not be using "return"?
function caseInSwitch(val) {
// Only change code below this line
switch (val) {
case 1:
return "alpha";
break;
case 2:
return "beta";
break;
case 3:
return "gamma";
break;
case 4:
return "delta";
break;
}

// Only change code above this line
}

// Change this value to test
caseInSwitch(3);
KTT-9898
@KTT-9898
May 17 2016 00:09
Hello.
Christian Todd
@chrstntdd
May 17 2016 00:09
@nickiowaspain instead of returning the string you can assign the empty string answer to that string for each case
so for instance:
KTT-9898
@KTT-9898
May 17 2016 00:09

Quick question. Instructions

Assign the value 7 to variable a.

Assign the contents of a to variable b.

Premdeep Saini
@premdeepsaini
May 17 2016 00:09
@nickiowaspain after return statemen
KTT-9898
@KTT-9898
May 17 2016 00:09

// Setup
var a = 7;
var b = 2;

// Only change code below this line

Premdeep Saini
@premdeepsaini
May 17 2016 00:10
@nickiowaspain after return statement the break statement is of no use
Christian Todd
@chrstntdd
May 17 2016 00:10
case n:
break;
Nick
@nickiowaspain
May 17 2016 00:11
ok thanks all!
Premdeep Saini
@premdeepsaini
May 17 2016 00:11
@KTT-9898 b=a;
Norvin Burrus
@ndburrus
May 17 2016 00:11
@KTT-9898 ..the first line is ok. the second line needs some attention. hint: "Assign ( = ) the contents of a to variable b."
Dustin
@Key-Banger
May 17 2016 00:11
@chrstntdd I think you want to do numArr.push(strArr[i].charCodeAt());
KTT-9898
@KTT-9898
May 17 2016 00:14
I'm still confused.
Christian Todd
@chrstntdd
May 17 2016 00:14
@Key-Banger Thanks! Now I've got everything pushed to the new blank array I have, but only the first value has been converted to a number, the rest are null. Do you know why this is?
CamperBot
@camperbot
May 17 2016 00:14
chrstntdd sends brownie points to @key-banger :sparkles: :thumbsup: :sparkles:
Premdeep Saini
@premdeepsaini
May 17 2016 00:16
This message was deleted
Dustin
@Key-Banger
May 17 2016 00:17
@chrstntdd did you take the "i" out of charCodeAt()?
Norvin Burrus
@ndburrus
May 17 2016 00:17
@KTT-9898 .. alright. = is an assignment operator. it means to assign whatever is on the right of =, to whatever is on the left side. so, a = 7 assigns the number seven to the var/iable a. then, b = a assigns the variable a's (specifically its' value) to the variable b... make sense?
Coy Sanders
@coymeetsworld
May 17 2016 00:17
@KTT-9898 look what @premdeepsaini has, that's how you assign the value of a to b
also what @ndburrus just wrote :thumbsup:
Premdeep Saini
@premdeepsaini
May 17 2016 00:18
var a=7;
var b;
b=a;
Santosh Kumar Toleti
@Santosh456
May 17 2016 00:18
can anyone help me toi solve these problem
KTT-9898
@KTT-9898
May 17 2016 00:19

// Setup
var a = 7;
var b = 2;
b = a;

// Only change code below this line

Christian Todd
@chrstntdd
May 17 2016 00:19
@Key-Banger I did not, but I just did. why would having the variable there cause each value after the first one to be null?
Coy Sanders
@coymeetsworld
May 17 2016 00:19
yup @KTT-9898
KTT-9898
@KTT-9898
May 17 2016 00:19
it doesn't let me pass lol
Norvin Burrus
@ndburrus
May 17 2016 00:20
@KTT-9898 the line var b = 2 isn't needed.... which challenge is this?
Coy Sanders
@coymeetsworld
May 17 2016 00:20
yeah maybe don't assign the b = 2 part, just do var b;
KTT-9898
@KTT-9898
May 17 2016 00:20
Storing Values with the Assignment Operator under Javascript
Coy Sanders
@coymeetsworld
May 17 2016 00:20
not that your code is wrong, FCC may not parse your solution correctly
KTT-9898
@KTT-9898
May 17 2016 00:21
It still doesn't pass. :(
Coy Sanders
@coymeetsworld
May 17 2016 00:21
oh i see
// Setup
var a;
var b = 2;
that part you leave alone
you need to do two things: set a to 7, then b to a
so there should be 4 lines total
Santosh Kumar Toleti
@Santosh456
May 17 2016 00:21
@Santosh456
https://www.freecodecamp.com/challenges/understand-string-immutability
can anyone help me toi solve these problem
Coy Sanders
@coymeetsworld
May 17 2016 00:22
see where it says // Only change code below this line? that means they don't want you touching var a; or var b=2
Norvin Burrus
@ndburrus
May 17 2016 00:22
@KTT-9898 alright. var a is already declared for you... so assign 7 to a first
@KTT-9898 var b is already assigned the value of 2 for you... so you just need to assign a to b. getting clearer? ... can you type in how we would assign a to b? that may be where the confusion is... clue: take a look at the last tests' comment... :)
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:25
3 days, and I finally got a polygon to display. It's pretty great. I wish this meant I had a better understanding, but I can't get anything else to work, like move it. http://codepen.io/NEETWizardJanus/pen/JXzeeq?editors=1010
KTT-9898
@KTT-9898
May 17 2016 00:25
a=b
Coy Sanders
@coymeetsworld
May 17 2016 00:25
other way around
you want b to equal the contents of a
before that though, you want to assign a the value of 7
KTT-9898
@KTT-9898
May 17 2016 00:26
oh thanks
Jared Abel
@jaredabel
May 17 2016 00:27
any reason why my setInterval never ticks?
$('#'+moves[i]).css({opacity:1}); setInterval(function(){$('#'+moves[i]).css({opacity:.1});

}, 1000);
Coy Sanders
@coymeetsworld
May 17 2016 00:27
no problem
KTT-9898
@KTT-9898
May 17 2016 00:27
thanks guys
Jared Abel
@jaredabel
May 17 2016 00:27
it does the first opacity change to 1, but never back to .1
rphares
@rphares
May 17 2016 00:28
@Santosh456 , still stuck?
Norvin Burrus
@ndburrus
May 17 2016 00:28
@KTT-9898 youre welcome... :+1:
Tulio Natale
@tuliodnw
May 17 2016 00:29
people im in the binary agents bonfire, (vhange binary to letters), i can do this challenge using switches for every letter, is the a better way to do it? thanks
Santosh Kumar Toleti
@Santosh456
May 17 2016 00:32
no
pls help me to solve these
EricOber
@EricOber
May 17 2016 00:33
hey everybody, can someone help me solve a challenge?
rphares
@rphares
May 17 2016 00:33
@Santosh456 , can you paste the code you are trying?
Santosh Kumar Toleti
@Santosh456
May 17 2016 00:33
i am nt able understanf=d the question
rphares
@rphares
May 17 2016 00:33
ah,
you need to make a sentence
you can do it by concatenating the parameters
Santosh Kumar Toleti
@Santosh456
May 17 2016 00:34
oh
rphares
@rphares
May 17 2016 00:34
be sure to concatenate in non-word characters (i suggest spaces)
so that the output isn't: bigdogranquickly
and, store the sentence in what you will return :blush:
thats it~
( @Am3ricanPaladin , not ignoring you, just think i recall you are passed what i can help with, sorry! :pensive: )
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:38
anyone know if I'm applying my JS library function's transform {rotate, X, and Y} on the wrong element? I can't get it to work. http://codepen.io/NEETWizardJanus/pen/JXzeeq?editors=1010
oh... I see... It's not accessing it properly at all. I tried moving the color changing from the first one to the later changes and it failed.
not sure how I'm supposed to edit existing variables then.
Dan Couper
@DanCouper
May 17 2016 00:41
@tuliodnw Yes, switch is not that useful in JS; you definitely shouldn't need it for this.
1. parseInt takes a second argument, the radix. 10 is decimal, so parseInt('2', 10) returns 2. If you use a radix of 2 on a binary?
Tulio Natale
@tuliodnw
May 17 2016 00:42
@DanCouper you lost me, whats parseInt?
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:42
uhg. I don't understand the syntax at all.
Aryan
@aryandua
May 17 2016 00:42
@aryandua
http://codepen.io/aryandua/pen/pymNbB?editors=1010
Hey guy I am writing a game in which you have to stop the ball from falling
Everything is working just three problems
One- The ball falls instantly
two- the plate goes with the ball
three- How do i recognize that the user has got the ball and stop the ball from falling?
Santosh Kumar Toleti
@Santosh456
May 17 2016 00:42
@rphares Iam trying but its not happening
Aryan
@aryandua
May 17 2016 00:42
@NEETWizardJanus did you make your clock?
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:42
why is it so hard to learn syntax?
rphares
@rphares
May 17 2016 00:42
@Santosh456 -- can you please paste what you are trying? :blush:
Dan Couper
@DanCouper
May 17 2016 00:42
1. The function String.fromCharCode(67), what does that return?
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:43
@aryandua are you kidding? It's taken me 3 days to get a polygon to appear. Now I'm trying to move and rotate it and make multiple ones. Who knows how many days that will take.
richiedSIS
@richiedSIS
May 17 2016 00:43
Hi there. I'm working on the challenge to determine a palindrome and I've met all the test cases except the last one. When I run it the regex is returning 0_000. How can I modify the regex to also get rid of the underscore?
Aryan
@aryandua
May 17 2016 00:43
its okay you'll get it @NEETWizardJanus
Dan Couper
@DanCouper
May 17 2016 00:43
@tuliodnw they are both functions, they're linked on the challenge
richiedSIS
@richiedSIS
May 17 2016 00:43

function palindrome(str) {
// Good luck!
if(str ===null)
return false;

var newStr = str.toLowerCase().replace(/\W/g,'');
//return newStr;
var left=0; var right=newStr.length-1;
while(left<right){
if(newStr[left]!==newStr[right])
return false;
left++;
right--;

}
return true;

}

palindrome("0_0 (: /-\ :) 0-0")
Aryan
@aryandua
May 17 2016 00:43
Nothing is impossible for you :)
@aryandua
http://codepen.io/aryandua/pen/pymNbB?editors=1010
Hey guy I am writing a game in which you have to stop the ball from falling
Everything is working just three problems
One- The ball falls instantly
two- the plate goes with the ball
three- How do i recognize that the user has got the ball and stop the ball from falling?
Tulio Natale
@tuliodnw
May 17 2016 00:44

String.prototype.charCodeAt()
String.fromCharCode()

Aryan
@aryandua
May 17 2016 00:44
Look I am failing to make a simple game
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:44
@aryandua I don't understand the syntax at all.
Aryan
@aryandua
May 17 2016 00:44
what syntax?
js?
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:44
I thought putting a . would just do more commands on the same parent element, but mine seem to cut off after the 2nd one.
Dan Couper
@DanCouper
May 17 2016 00:45
@NEETWizardJanus what you're trying to do is hard, you're doing well; I get the same massive raging frustration and I've been programming for a few years. It gets easier
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:45
I dunno if it's JS or jQuery.
Santosh Kumar Toleti
@Santosh456
May 17 2016 00:45
Aryan
@aryandua
May 17 2016 00:45
both are easy if you follow Fcc
Rafi Ronquillo
@RafiTranquilo
May 17 2016 00:45
Having trouble with "Profile Lookup". Can anyone point me in the right direction?
//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 lookUp(firstName, prop){
// Only change code below this line
var flag = false;
for(var i = 0; i <contacts.length; i++){
if(firstName === contacts[i].firstName){
if(contacts[i].hasOwnProperty(prop)){
flag = true;
return contacts[i][prop];
}
else {
return "No such property";
}
}
}
if(flag ===false) return "No such contact";
// Only change code above this line
}

// Change these values to test your function
lookUp("Bob", "number");
Aryan
@aryandua
May 17 2016 00:45
@NEETWizardJanus do you do FCC as a side study?
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:45
and then you get stuff like .transform({
x: (segwid * 2),
y: (seglen)
});
@aryandua no idea what that is.
Aryan
@aryandua
May 17 2016 00:46
whoa! that does look complecated
rphares
@rphares
May 17 2016 00:46
actually, it just doesn't like that you have two string pieces next to each other, @Santosh456 --
put that first space in the "" from "The"
Aryan
@aryandua
May 17 2016 00:46
@NEETWizardJanus try making that same clock in C++ again :0
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:46
I mean it's my broken code, but I do see stuff LIKE that. I just can't tell when it's used or not used.
rphares
@rphares
May 17 2016 00:46
(write "The " ) @Santosh456
Dan Couper
@DanCouper
May 17 2016 00:46
rphares
@rphares
May 17 2016 00:47
so that you can have "The " + myNoun... @Santosh456
then you will be fine~
Blake Harris
@bharris62
May 17 2016 00:47
I am having trouble returing the correct description on my twitch app, can someone take a look at it and give me some fresh eyes? thanks!
http://codepen.io/bharris62/pen/regWmV
Dan Couper
@DanCouper
May 17 2016 00:47
If you give the binary to parseInt, you get a number, if you pass that number to String.fromCharCode, you get a character
@tuliodnw
Tulio Natale
@tuliodnw
May 17 2016 00:48
@DanCouper thanks didnt know about that one, was about to do it the mathematical way thanks
CamperBot
@camperbot
May 17 2016 00:48
tuliodnw sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
Norvin Burrus
@ndburrus
May 17 2016 00:49
@RafiTranquilo instead of a final (additional) if statement, you could just use another else statement... :) [instead of using flag as a flow control method]
Santosh Kumar Toleti
@Santosh456
May 17 2016 00:51
@rphares can u tell me what exactly i should write
i am trying but its not happening
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:52
I remember in C++ someone gave me ASM code to change video modes and write pixels directly. I have a feeling there's a good chance any graphical library will needlessly complicate the matter much like it's doing with web coding.
I coded functions to draw lines using the ASM code to write individual pixels.
So much easier compared to this nonsense.
rphares
@rphares
May 17 2016 00:52
in this case, yes, i will, :blush: because your code was actually okay, the test was a little off-- can you send a new link, @Santosh456 ? because you changed something, i cant open it anymore ... :pensive:
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:52
which is probably why I liked microprocessor programming in college. :P
Dan Couper
@DanCouper
May 17 2016 00:53
@tuliodnw :thumbsup: yea, plus it's not obvious what the parseInt function does: most of the time it's just used for converting numbers trapped in strings to real numbers
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:53
and I always hated libraries. It's like trying to get into the mind of a unique madman.
No two are alike!
Rafi Ronquillo
@RafiTranquilo
May 17 2016 00:53
@ndburrus thanks, I'll try that
CamperBot
@camperbot
May 17 2016 00:53
rafitranquilo sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:56
well I'm back to feeling like a failure who can't do anything. getting one polygon to display is the extent of my skills.
Aryan
@aryandua
May 17 2016 01:01
dont feel that way
Wiktor
@Wkredz1
May 17 2016 01:04
.replace (/\w\S* what is this what does it mean?
Zach
@Moose1551
May 17 2016 01:04
Is there any reason why my final "else" statement isn't returning the entire string length in the bonfire challenge "Truncate a String"?
function truncateString(str, num) {
var stringEnd = "...";
if (num > 3) {
return str.slice(0, num - 3) + stringEnd;
} else if (num <= 3) {
return str.slice(0, num) + stringEnd;
} else {
return str;
}

}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
Diogo Righi
@diogorighi
May 17 2016 01:07
it's never getting to the else statement
you shoud verify if the num is equal to the length of the string
if I remember wel...
well
the num will always be >3 or <=3! so in your code, it will never reach the else statement
Victor
@abeledovictor
May 17 2016 01:09
HI guys! I need help with the nextInLine challenge (Stand in line)
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));
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.
I dont know what to write :(
Destineees
@Destineees
May 17 2016 01:14
So I am working on the palindrome challenge and I am a little confused. I passed all the tests except the last one "palindrome("0_0 (: /-\ :) 0-0") should return true." Can anyone give me a hint how to pass this test when the notes say to remove all punctuation spaces and symbols?
eeflores
@eeflores
May 17 2016 01:15
@Destineees if you're using \W in the regexp, it includes underscore
@moigithub
May 17 2016 01:16
Greg
@GregJacoby
May 17 2016 01:16
@Destineees exactly! test what your new string is outputting in the console, and you'll probably see that the underscore is still hanging around...
i'm doing the truncate a string challenge, can someone explain to me exactly what I'm supposed to do?

function truncateString(str, num) {
if(str.length > num) {
var truncStr = str.slice(0, num);
return truncStr + "...";
}
return str;
}
@moigithub
May 17 2016 01:17
Diego Mayer
@Chrono79
May 17 2016 01:17
@abeledovictor look at the previous challenges involving array methods, push, pop, shift and unshift
Greg
@GregJacoby
May 17 2016 01:17
but for truncateString("Peter Piper picked a peck of pickled peppers", 14) it returns "peter piper pi..." which is what I thought it's supposed to do, but the challenge wants it to return "Peter Piper..." what am i misunderstanding about what they want me to do?
Destineees
@Destineees
May 17 2016 01:18
@eeflores @GregJacoby Thanks
CamperBot
@camperbot
May 17 2016 01:18
destineees sends brownie points to @eeflores and @gregjacoby :sparkles: :thumbsup: :sparkles:
eeflores
@eeflores
May 17 2016 01:18
@GregJacoby the "..." are included in the length of the truncated string
Greg
@GregJacoby
May 17 2016 01:18
@eeflores I know it says that, but I don't understand what they mean. How is it possible the ... is included in anything since all I'm doing is adding it onto the end of the returned value?
eeflores
@eeflores
May 17 2016 01:19
so it's like num - 3
Greg
@GregJacoby
May 17 2016 01:19
i see how that fixes my original problem, but im not understanding it conceptually
help? xD
CamperBot
@camperbot
May 17 2016 01:20
no wiki entry for: xd
Diego Mayer
@Chrono79
May 17 2016 01:20
@GregJacoby instead of cutting at position 14 and adding the 3 dots, cut at 14-3 and add the 3 dots
Victor
@abeledovictor
May 17 2016 01:20
@moigithub @Chrono79 thanks
CamperBot
@camperbot
May 17 2016 01:20
abeledovictor sends brownie points to @moigithub and @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1163 | @moigithub |http://www.freecodecamp.com/moigithub
Greg
@GregJacoby
May 17 2016 01:20
OH
eeflores
@eeflores
May 17 2016 01:20
that's what's needed to pass the exercise. Unfortunately there's a little more to it, because you have to take into consideration strings shorter than 3 chars
Greg
@GregJacoby
May 17 2016 01:20
OHHhhHh
@Chrono79 @eeflores thank you, i understand the whole thing now
CamperBot
@camperbot
May 17 2016 01:21
gregjacoby sends brownie points to @chrono79 and @eeflores :sparkles: :thumbsup: :sparkles:
eeflores
@eeflores
May 17 2016 01:21
good stuff
Zach
@Moose1551
May 17 2016 01:23
@diogorighi, thank you for helping me locate the problem area. I tried to fix that issue, but I'm having trouble understanding why my newer solution isn't working. Could you shed some light?
function truncateString(str, num) {

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

}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
CamperBot
@camperbot
May 17 2016 01:23
moose1551 sends brownie points to @diogorighi :sparkles: :thumbsup: :sparkles:
EricOber
@EricOber
May 17 2016 01:25
is anyone knowledgeable about the object oriented programming challenges?
i need help
eeflores
@eeflores
May 17 2016 01:27
@Moose1551 do the if(num > str.length) test first
otherwise you'll be adding the "..."s when you don't need to
EricOber
@EricOber
May 17 2016 01:28
hey @eeflores i am working on "Make Unique Objects by Passing Parameters to our Constructor" and i think i have my code wrong

var Car = function(wheels, seats, engines) {
//Change this constructor
this.wheels = 4;
this.seats = 1;
this.engines = 1;
};

//Try it out here
var myCar = new Car(4, 1, 1);
Arvilyn Ong
@arvilyn
May 17 2016 01:29
hi, could anyone help with 'Check for Palindromes' challenge? i have no idea why it doesn't return false
function palindrome(str) {
// Good luck!
str.trim(); //RaceCar = RaceCar
str.toLowerCase(); //RaceCar = racecar
arr1 = str.split(''); // r a c e c a r
arr2 = arr1.reverse(); // r a c e c a r
if ((arr1.join('')) === (arr2.join(''))) {
return true;
} else {
return false;
}
}

palindrome("eye");
eeflores
@eeflores
May 17 2016 01:30
@Am3ricanPaladin assign the parameters of the function to the this values eg. this.wheels = wheels;
Diego Mayer
@Chrono79
May 17 2016 01:30
@arvilyn I think you have to assign str.toLowerCase() to str, because toLowerCase doesn't modify the string:
Syntax
str.toLowerCase()
Description
The toLowerCase() method returns the value of the string converted to lowercase. toLowerCase() does not affect the value of the string str itself.
Also, you have to get rid of all that isn't a letter or a number for pasing all tests, use replace + regex to do that
EricOber
@EricOber
May 17 2016 01:31


var Car = function(wheels, seats, engines) {
//Change this constructor
this.wheels = wheels;
this.seats = seats;
this.engines = engines;
};

//Try it out here
var myCar = new Car(4, 1, 1);
like that?
eeflores
@eeflores
May 17 2016 01:31
yeah - does it work?
EricOber
@EricOber
May 17 2016 01:31
hey it does, thanks @eeflores
CamperBot
@camperbot
May 17 2016 01:31
am3ricanpaladin sends brownie points to @eeflores :sparkles: :thumbsup: :sparkles:
eeflores
@eeflores
May 17 2016 01:31
yay
EricOber
@EricOber
May 17 2016 01:31
now i am wonder why it works LOL
VultureBetrayer
@VultureBetrayer
May 17 2016 01:32
@Am3ricanPaladin if you run into that, try and go back a couple lessons, and redo them, there's probably a step you did prior that you didn't realize was necessary (that's been my experience)
EricOber
@EricOber
May 17 2016 01:33
oh ok
Victor
@abeledovictor
May 17 2016 01:40


function nextInLine(arr, item) {
var cars = ["ford", "chevrolet", "nissan", "suzuki", "ferrari"];
var carsn = [5];// Your code here
cars.push("carsn");
cars.shift();
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));
still cant complete the challenge u.u
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.
Diego Mayer
@Chrono79
May 17 2016 01:40
@abeledovictor why those vars?
use only arr and item
Victor
@abeledovictor
May 17 2016 01:43
function nextInLine(arr, item) {
var arr;
var item;
arr.push(item);
arr.shift();
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));
@Chrono79
like that?? i dont know what im missing
Stephen James
@sjames1958gm
May 17 2016 01:51
@abeledovictor Don't redefine arr or item they come with the function defintion, also return the result of arr.shift()
William Coleman
@wcski
May 17 2016 01:52
Hmm
stuck on challenge 216, Return Early Pattern for functions
rphares
@rphares
May 17 2016 01:53
@wcski ,hiya!
can you paste what you are trying?
William Coleman
@wcski
May 17 2016 01:53
Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.
rphares
@rphares
May 17 2016 01:53
yep-- you just need to make an if statement,
that says something like,
William Coleman
@wcski
May 17 2016 01:53

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

return c;

} 

rphares
@rphares
May 17 2016 01:54
oh, sooo close,
William Coleman
@wcski
May 17 2016 01:54
formatting in gitter never works for me heh
Zach
@Moose1551
May 17 2016 01:54
@eeflores, Thank you for the help. I'm passing the first four tests now, but for some reason I can't pass the last two tests. Any advice? I don't understand why the "else if" part isn't working...
 function truncateString(str, num) {

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

}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
CamperBot
@camperbot
May 17 2016 01:54
moose1551 sends brownie points to @eeflores :sparkles: :thumbsup: :sparkles:
William Coleman
@wcski
May 17 2016 01:54

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

return c;

} 

rphares
@rphares
May 17 2016 01:54
but why return c? @wcski
just return exactly what it told you to...
William Coleman
@wcski
May 17 2016 01:54
well my rationale there was that c is undefined
rphares
@rphares
May 17 2016 01:55
heh, yeah, i get that... but you should be fine returning undefined or just return
Victor
@abeledovictor
May 17 2016 01:55
@sjames1958gm @Chrono79 thanks
CamperBot
@camperbot
May 17 2016 01:55
abeledovictor sends brownie points to @sjames1958gm and @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: abeledovictor already gave chrono79 points
:star2: 1125 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
William Coleman
@wcski
May 17 2016 01:55
Ohhh
thanks @rphares
CamperBot
@camperbot
May 17 2016 01:56
wcski sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star2: 4644 | @rphares |http://www.freecodecamp.com/rphares
rphares
@rphares
May 17 2016 01:56
sure thing~ Happy coding!
Wiktor
@Wkredz1
May 17 2016 01:56
If we didn't split the string how does it know that it takes the first letter?
William Coleman
@wcski
May 17 2016 01:56
Do they pay you to monitor this room lol?
Wiktor
@Wkredz1
May 17 2016 01:56

function titleCase(str) {
return str.replace(/\w\S*/g, function(w) {
return w.charAt(0).toUpperCase() + w.substr(1).toLowerCase();
});
}

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

Arvilyn Ong
@arvilyn
May 17 2016 01:57
@Chrono79 thank you!! but my code doesn't seem to work after modifying it.. could you help me again? haha
function palindrome(str) {
// Good luck!
var removedNAC = str.replace(/\W/g, '');
str = removedNAC.toLowerCase(); //RaceCar = racecar
arr1 = str.split(''); // r a c e c a r
arr2 = arr1.reverse(); // r a c e c a r
if ((arr1.join('')) === (arr2.join(''))) {
return true;
} else {
return false;
}
}

palindrome("not a palindrome");
CamperBot
@camperbot
May 17 2016 01:57
arvilyn sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
Diego Mayer
@Chrono79
May 17 2016 01:59
@arvilyn \w includes _ you have to get rid of the underscore too to pass the last test
also you could return your if condition directly, just check the number of () I think it's wrong
buiphuking
@buiphuking
May 17 2016 02:03
@Chrono79
i have solution ,
0.2 0.2 = 0.04000000001
Math.round(0.2
0.2 *100) /100 = 0.04
Diego Mayer
@Chrono79
May 17 2016 02:04
@buiphuking :+1:
have you solved the multiple points problem?
Bearded One
@EpicBeard
May 17 2016 02:05
function palindrome(str) {
str = String.replace(" ", "");
str = String.toLowerCase();

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

}

palindrome("eye");
any reason this doesn't work?
Diego Mayer
@Chrono79
May 17 2016 02:05
@tom103 yes, you have to get rid of anything that's not a number or a letter
Bearded One
@EpicBeard
May 17 2016 02:05
ah....hmmmmm
Diego Mayer
@Chrono79
May 17 2016 02:06
and don't use String.replace use str.replace (the same for toLowerCase)
buiphuking
@buiphuking
May 17 2016 02:06
@Chrono79
http://codepen.io/buiphuking/pen/qZwpjE?editors=0010
spend 10s and test for me , tell me your thought
Zach
@Moose1551
May 17 2016 02:07

Okay, so I switched around the "if" and the "else if" statement. Example 1 does not work. Example 2 does. Can anyone explain a bit why switching the statements affected the outcome?
Example 1:

function truncateString(str, num) {

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

}

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

Example 2:

function truncateString(str, num) {

var stringEnd = "...";

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

}
truncateString("A-tisket a-tasket A green and yellow basket", 11);
Bearded One
@EpicBeard
May 17 2016 02:07
been stuck on palindromes for a long time now
think I'll just skip it
Wise
@WiseNN
May 17 2016 02:07
Hey everyoneβ¦.Can someone please tell me why my array at index βiβ is not copying the element, its copying the entire ??? (At line 1)
function diffArray(arr1, arr2) {
var newArr = [];

if(arr1.length<arr2.length)
{
newArr=arr2;
arr2=arr1;
arr1=newArr;
}

for(var i=0; i<arr1.length;i++)
{
var see = arr1[i];
if(arr2.indexOf(see)=== -1)
{
newArr=arr2[i]; //<<<---- This Line 1
}
}
return newArr;
}
Diego Mayer
@Chrono79
May 17 2016 02:08
@buiphuking try to fix the multiple symbols, ...., **, -----, ++++
Arvilyn Ong
@arvilyn
May 17 2016 02:09
@Chrono79 does str.replace(/[^0-9a-z]/gi, '') remove all non-alphanumeric characters??
Diego Mayer
@Chrono79
May 17 2016 02:09
@arvilyn yes
Stephen James
@sjames1958gm
May 17 2016 02:10
@arvilyn yes
Arvilyn Ong
@arvilyn
May 17 2016 02:10
all my tests pass except for those who were supposed to return false... is there any problem with the code?
Diego Mayer
@Chrono79
May 17 2016 02:10
@tom103 you're not so far, look, @arvilyn is doing the same challenge
Stephen James
@sjames1958gm
May 17 2016 02:12
@arvilyn reverse reverses the array in place, so arr2 and arr1 are the same array. compare arr2.join to str
William Coleman
@wcski
May 17 2016 02:13
Things are starting to get difficult here. I like it. Counting cards...any hints?
Bearded One
@EpicBeard
May 17 2016 02:14


function palindrome(str) {
// Good luck!
str.replace(/[^0-9a-z]/gi, '');
str.replace(" ", "");
str.toLowerCase();

if (str != str.reverse()) {
return false;
} else {

return true;
}
}
I drop all non letter characters, then replace remove the spaces. Then I check to see that if the str isn't equal to the string in reverse etc....
not sure why that doesn't work
Arvilyn Ong
@arvilyn
May 17 2016 02:14
omg i finally solved it thanks @sjames1958gm @Chrono79 !!!! :smile:
CamperBot
@camperbot
May 17 2016 02:14
arvilyn sends brownie points to @sjames1958gm and @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: arvilyn already gave chrono79 points
:star2: 1126 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
May 17 2016 02:14
@tom103 string doesn't have a reverse function.
Subh Samal
@subhsamal
May 17 2016 02:14
can anyone help on "Using Objects for Lookups"
Stephen James
@sjames1958gm
May 17 2016 02:14
@wcski most have used a switch statement.
Bearded One
@EpicBeard
May 17 2016 02:14
crud
so assign them to arrays and flip the array then compare?
jgoldverg
@jgoldverg
May 17 2016 02:15
can anyone explain how the toggleClass function works in jquery i tried to read up on it but its confusing me very badly
rphares
@rphares
May 17 2016 02:15
if/else or switch, either way increment and decrement as instructed, dont return till the end, with an if/else based on count, and be sure to include a space at the beginning of your strings, @wcski ~
Stephen James
@sjames1958gm
May 17 2016 02:15
@tom103 yes
rphares
@rphares
May 17 2016 02:15
Bearded One
@EpicBeard
May 17 2016 02:15
ok, gonnat try it
jgoldverg
@jgoldverg
May 17 2016 02:15
$("flash").click(function(){$("p").toggleClass('laser');
});
Subh Samal
@subhsamal
May 17 2016 02:15
var lookup = {
"bravo": "Boston",
"charlie": "Chicago",
"delta": "Denver",
"echo": "Easy",
"foxtrot": "Frank",
"": undefined };
lookup[val];
Stephen James
@sjames1958gm
May 17 2016 02:15
@rphares That's all the hints :)
jgoldverg
@jgoldverg
May 17 2016 02:15
i feel like this is correct but im getting an error
rphares
@rphares
May 17 2016 02:16
two things, @subhsamal -
Subh Samal
@subhsamal
May 17 2016 02:16
yes plz
Stephen James
@sjames1958gm
May 17 2016 02:16
@jgoldverg is flash a class or id?
rphares
@rphares
May 17 2016 02:16
(yeah, heavy handed, but those arent the thinking errors... @sjames1958gm :blush:)
Diego Mayer
@Chrono79
May 17 2016 02:16
@tom103 also, assign back str.replace and str.toLowerCase to str
replace: This method does not change the String object it is called on. It simply returns a new string.
The toLowerCase() method returns the value of the string converted to lowercase. toLowerCase() does not affect the value of the string str itself.
jgoldverg
@jgoldverg
May 17 2016 02:16
class
rphares
@rphares
May 17 2016 02:16
first, a minor thing, @subhsamal , you dont need "": undefined, you can get ride of that guy
second a big thing
Stephen James
@sjames1958gm
May 17 2016 02:16
@jgoldverg missing a character that identifies it as a class in the jquery selector
rphares
@rphares
May 17 2016 02:16
what are you returning? @subhsamal
Subh Samal
@subhsamal
May 17 2016 02:17
return statement is there
jgoldverg
@jgoldverg
May 17 2016 02:17
really which char?
Stephen James
@sjames1958gm
May 17 2016 02:17
@jgoldverg .
William Coleman
@wcski
May 17 2016 02:17
cool thanks @sjames1958g. That's the path I'm on. Just wondering how much logic I can put into my cases. Thinking I need to increment, and put a check in to see if the count is ps, neg or == 0, but I'm not sure if i can or even need to put all that into each case.
CamperBot
@camperbot
May 17 2016 02:17
wcski sends brownie points to @sjames1958g :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for sjames1958g
rphares
@rphares
May 17 2016 02:17
right-- but it is return result, right @subhsamal
Subh Samal
@subhsamal
May 17 2016 02:17
yes
rphares
@rphares
May 17 2016 02:17
what does result = ?
jgoldverg
@jgoldverg
May 17 2016 02:17
@sjames1958gm ohh lol thx
CamperBot
@camperbot
May 17 2016 02:17
jgoldverg sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1127 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
rphares
@rphares
May 17 2016 02:17
in your code right now, as it is?
William Coleman
@wcski
May 17 2016 02:17
But this is really just me talking out loud, no real need to respond
Zaw Ye Htut
@yeyezaw
May 17 2016 02:18
Does anyone give some more hint for "where do I belong" challenge ? I'm stuck in that and no clue how to sort and return .
Stephen James
@sjames1958gm
May 17 2016 02:18
@wcski the checks can go after the switch rather than in the case, all cases share the test on count.' << don't look at this
Subh Samal
@subhsamal
May 17 2016 02:19
@rphares Do I have to change lookup to result in my code ?
rphares
@rphares
May 17 2016 02:19
no-
you have what you want, lookup[val]
but... its just sitting there
Subh Samal
@subhsamal
May 17 2016 02:20
assign to result ?
rphares
@rphares
May 17 2016 02:20
:blush:
Subh Samal
@subhsamal
May 17 2016 02:20
let me try :)
Diego Mayer
@Chrono79
May 17 2016 02:21
@yeyezaw you could insert the value to the array, sort it (you have to use a function to sort numbers) and use indexof to find the index
Y'Eli Buonya
@yeli-buonya
May 17 2016 02:21
Can someone help me get started with the 'Record Collection' challenge?
Wiktor
@Wkredz1
May 17 2016 02:21
IM GETTING AN ERROR "String,split is not a function"
String.split(" ");
Zaw Ye Htut
@yeyezaw
May 17 2016 02:21
Ok, let me try it @Chrono79
rphares
@rphares
May 17 2016 02:21
just get started, or you have some code that isn't working, @yeli-buonya ?
Y'Eli Buonya
@yeli-buonya
May 17 2016 02:23
@rphares i've deleted and tried mulitple lines of code. I was using if/ else if statements
rphares
@rphares
May 17 2016 02:23

to get started, i'd turn these three instructions into conditions ...
If value is non-blank (value !== "") and prop is not "tracks" then update or set the value for the prop.

If the prop is "tracks" and value is non-blank, push the value onto the end of the tracks array.

If value is blank, delete that prop.

if/else will work, @yeli-buonya
another thing that might be useful--
Stephen James
@sjames1958gm
May 17 2016 02:23
@Wkredz1 You use split on a string not on the String object.
Subh Samal
@subhsamal
May 17 2016 02:23
Did it :blush: @rphares Thank you
CamperBot
@camperbot
May 17 2016 02:23
subhsamal sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star2: 4645 | @rphares |http://www.freecodecamp.com/rphares
rphares
@rphares
May 17 2016 02:24
https://medium.com/@prufrock123/js-dot-notation-vs-bracket-notation-797c4e34f01d#.48e3a17a0 helped me understand why bracket not dot is so important in record collection @yeli-buonya
Y'Eli Buonya
@yeli-buonya
May 17 2016 02:24
@rphares how would I check for a non-blank? I guess i'm just really exhausted
rphares
@rphares
May 17 2016 02:24
Awesome! Congrats and happy coding, @yeli-buonya ~
Y'Eli Buonya
@yeli-buonya
May 17 2016 02:24
@rphares I'll go over that lesson again, thanks!
CamperBot
@camperbot
May 17 2016 02:24
yeli-buonya sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
Subh Samal
@subhsamal
May 17 2016 02:24
@rphares can you explain a bit about undefined one ?
CamperBot
@camperbot
May 17 2016 02:24
:star2: 4646 | @rphares |http://www.freecodecamp.com/rphares
Stephen James
@sjames1958gm
May 17 2016 02:24
@yeli-buonya this hint is provided on how to test non-blank -> (value !== "")
Subh Samal
@subhsamal
May 17 2016 02:25
does it takes itself if not mentioned with in object ?
Y'Eli Buonya
@yeli-buonya
May 17 2016 02:26
@sjames1958gm my goodness, I guess i was doing something right
rphares
@rphares
May 17 2016 02:26
@subhsamal , not really, I'm not terribly good at explanations, i just pass on links, heh... @sjames1958gm will be better for that! :pensive:
Stephen James
@sjames1958gm
May 17 2016 02:26
@rphares Where did that bus come from :)
rphares
@rphares
May 17 2016 02:26
lol, observation :blush:
Subh Samal
@subhsamal
May 17 2016 02:27
@rphares that's fi9 ..I'll figure it out. thanks for your help :blush:
CamperBot
@camperbot
May 17 2016 02:27
subhsamal sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:warning: subhsamal already gave rphares points
rphares
@rphares
May 17 2016 02:27
(i totally cant explain anything, thats parta why I hang out... one of those who can write answers easily enough but doesn't understand well enough to explain, hence slowing down, reading a lot, and hanging out in the help rooms :blush: )
Stephen James
@sjames1958gm
May 17 2016 02:27
@subhsamal Where did "" : undefined come from?
Wiktor
@Wkredz1
May 17 2016 02:28
How do I make it so my string is split into words so I can every I can make every first letter of the words capitalized ???????????????????????????????????
Stephen James
@sjames1958gm
May 17 2016 02:28
str.split(" ")
@Wkredz1 :point_up:
Subh Samal
@subhsamal
May 17 2016 02:29
@sjames1958gm I did so only to match condition : phoneticLookup("") should equal undefined
Stephen James
@sjames1958gm
May 17 2016 02:30
Ah. The idea is that if the property is not in the lookup object it will return undefined. You were not supposed to add it.
@subhsamal I would have used something like phoneticLookup("zulu"); rather than the "" which is a bit confusing.
Subh Samal
@subhsamal
May 17 2016 02:31
you mean any property not present within object is undefined ?
Stephen James
@sjames1958gm
May 17 2016 02:31
@subhsamal basically, the value of x["y"] where "y" is not defined on x is undefined.
Subh Samal
@subhsamal
May 17 2016 02:32
make sense to me @sjames1958gm
Stephen James
@sjames1958gm
May 17 2016 02:32
:+1:
Subh Samal
@subhsamal
May 17 2016 02:32
thank you @sjames1958gm
CamperBot
@camperbot
May 17 2016 02:32
subhsamal sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1128 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Wiktor
@Wkredz1
May 17 2016 02:34
Its not working
Kyle W Pilkinton
May 17 2016 02:35
hey guys im on the wikipedia viewer project and im not sure how to work with the api. is there anywhere i can get backgroung knowledge
?
Stephen James
@sjames1958gm
May 17 2016 02:37
@Wkredz1 Post your code if you want us to take a look
help format
CamperBot
@camperbot
May 17 2016 02:38

## :point_right: code formatting [wiki]

### Multi line Code

js β¦ Type 3 backticks and then press [shift + enter β] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

 β¦ Type 3 backticks, then press [enter β]

### Single line Code

This an inline <paste code here> code formatting with a single backtick() at start and end around the code.

See also: β How to type Backticks | β― Compose Mode | β Gitter Formatting Basics

William Coleman
@wcski
May 17 2016 02:38
need a quick best practice or 'code review' on my (working) solution to card counter
switch(card) { case 2: case 3: case 4: case 5: case 6: count++; break; case 7: case 8: case 9: count = count; break; case 10: case 'J': case 'Q': case 'K': case 'A': count--; break; }
switch(card) { case 2: case 3: case 4: case 5: case 6: count++; break; case 7: case 8: case 9: count = count; break; case 10: case 'J': case 'Q': case 'K': case 'A': count--; break; }
switch(card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;
case 7:
case 8:
case 9:
count = count;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count--;
break;
}
Diego Mayer
@Chrono79
May 17 2016 02:39

@wcski delete this:

    case 7:
case 8:
case 9:
count = count;
break;

it does nothing

William Coleman
@wcski
May 17 2016 02:39
nice! got it formatting corectly, thanks @camperbot. anyway, that count = count statemtn core cases 7 8 and 9 seems redundant
CamperBot
@camperbot
May 17 2016 02:39
wcski sends brownie points to @camperbot :sparkles: :thumbsup: :sparkles:
:star2: 1734 | @camperbot |http://www.freecodecamp.com/camperbot
William Coleman
@wcski
May 17 2016 02:39
that's what i was thinking @Chrono79, thanks
CamperBot
@camperbot
May 17 2016 02:39
wcski sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
Stephen James
@sjames1958gm
May 17 2016 02:39
@wcski Looks good, the count = count is not needed. But you may want to keep case 7, 8, 9 so you know that they are covered.
CamperBot
@camperbot
May 17 2016 02:39
William Coleman
@wcski
May 17 2016 02:40
if I kep the 7 8 and 9 cases @sjames1958gm would I just put a break in there?
and nothing else?
Diego Mayer
@Chrono79
May 17 2016 02:40
yes, keep the break;
Stephen James
@sjames1958gm
May 17 2016 02:41
@sjames1958gm yeah, but if I understand how js works they would cause extra processing. In something like c or c++ they are probably optimized out, not sure about js
William Coleman
@wcski
May 17 2016 02:42
Stephen James
@sjames1958gm
May 17 2016 02:42
@wcski FYI, there is a pretty active web development community out your way. I know of several web dev podcasts that originate out of Utah, maybe even SLC
rphares
@rphares
May 17 2016 02:42
(dunno, is it too soon? ty @sjames1958gm ~)
CamperBot
@camperbot
May 17 2016 02:42
rphares sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1129 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
May 17 2016 02:43
@sjames1958gm Probably a free code camp meetup out there as well
William Coleman
@wcski
May 17 2016 02:43
There sure is. I work as a QA engineer out here, and the tech market is great. I was listening to a CodeNewbie podcast episode where she interviewed someone who ran a podcast locally. I think it was ruby-focused, though, so I didn't follow.
We have a great freecodecamp meetup group out here. just met up this past weekend.
Stephen James
@sjames1958gm
May 17 2016 02:44
@wcski devchat.tv has several podcasts - and their address is 514 South 2970 West β’ Lehi, UT 84043
@wcski Yeah, here in N. Texas it is not so great.
Ok. that's it for me tonight. Have a good one all
jgoldverg
@jgoldverg
May 17 2016 02:45
Are there many freecodecamps in nyc??
or near it?
William Coleman
@wcski
May 17 2016 02:45
For a newbie, I have to say that I really underestimated the value of getting involved with the community.
Stephen James
@sjames1958gm
May 17 2016 02:45
@jgoldverg Don't know but I would think so.
William Coleman
@wcski
May 17 2016 02:45
Thanks again for your help @sjames1958gm
CamperBot
@camperbot
May 17 2016 02:45
wcski sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1130 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
jgoldverg
@jgoldverg
May 17 2016 02:46
will def check it out
Chuck Pierce
@ChuckPierce
May 17 2016 02:47
bot help
CamperBot
@camperbot
May 17 2016 02:47

# Coding Help

I started this list while doing Algorithms, noticing a few things that were common issues / questions but I think most of them are going to be useful to people coding in general. If you've got some tips to help people code I'd love to hear them.

1. If you don't know where to start, write some pseudocode. Plan out the logic you're trying to implement in your native language before you try to put it into code.

2. Comment your code! Can't stress that one enough, if you get lost or take a break then come back you need to know what your code is trying to do. It will also reinforce what the code means to you, and help other people understand what your code does if you get stuck and ask for help. If you've got a any other tips for campers I'd love to see them!

3. Use the chrome javascript debugger console in conjunction with something like the netbeans IDE or sublime text to write your code. Both are free to download.
The FreeCodeCamp code editor is great but you can get a lot more feedback on your code's behaviour by using chrome's JS debugger and a bunch of console.log(myVariableGoesHere);

References

4. Posting your code in gitter is as simple as adding a line consisting of only



Then your code on the next lines, followed by a final

skilescm
@skilescm
May 17 2016 02:53
hello!
Ronique Ricketts
@RoniqueRicketts
May 17 2016 02:56
help factorialize a number
CamperBot
@camperbot
May 17 2016 02:56

# Problem Explanation:

Return the factorial of the provided integer. If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n.

Factorials are often represented with the shorthand notation n!

For example: 5! = 1 * 2 * 3 * 4 * 5 = 120

skilescm
@skilescm
May 17 2016 02:57
Anyone have any experience changing CSS with javascript?
OneRandomJamie
@OneRandomJamie
May 17 2016 02:59
I am completely stuck on the Word Blanks challenge.
rphares
@rphares
May 17 2016 02:59
@OneRandomJamie -- it gets lots of people,
could you please paste what you are trying? :blush:
OneRandomJamie
@OneRandomJamie
May 17 2016 03:00
This is what I have now but I tried what seems like 50000 other things before this. var myNoun = "cat";
var myVerb = "hit";
var Str = "The" + myAdjective + myNoun + "ran + myAdverb + "across the street and" + myVerb + "the dog.";
rphares
@rphares
May 17 2016 03:01
a few things,
first, you dont need to declare the myNoun, myAdjective stuff,
you can delete all the lines but var Str
second, for that line, you do need to store the sentence... but store it in what you will return--
look at the bottom, what are you going to return?
third, you are missing a " after "ran
OneRandomJamie
@OneRandomJamie
May 17 2016 03:03
@rphares wordBlanks("dog", "big", "ran", "quickly");
rphares
@rphares
May 17 2016 03:03
yep, i know the challenge :blush:
but-- the return statement has already been given to you,

// Your code above this line
return result;
}
so, if you store the sentence in a new var, myStr, it doesn't do you any good...
because you are going to return result
and at the top,
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
(also, did you change the parameters? that ^^ is what was there originally, no?)
OneRandomJamie
@OneRandomJamie
May 17 2016 03:06
@rphares its still there. I didnt change it. I just didnt copy it because it said dont change it.
rphares
@rphares
May 17 2016 03:06
Theres still more to do, but thats a lot... have another look-- i'd suggest resetting the lesson and giving it another go-
okay, cool
OneRandomJamie
@OneRandomJamie
May 17 2016 03:07
@rphares Thank you
CamperBot
@camperbot
May 17 2016 03:07
onerandomjamie sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
rphares
@rphares
May 17 2016 03:07
then, the lsat thing, on top of the other sutff-
CamperBot
@camperbot
May 17 2016 03:07
:star2: 4649 | @rphares |http://www.freecodecamp.com/rphares
rphares
@rphares
May 17 2016 03:07
so, even if you had all the changes above, it still wouldn't pass,
because your output would be Thebigdogranquicklyacross the street andranthe dog @OneRandomJamie
OneRandomJamie
@OneRandomJamie
May 17 2016 03:08
@rphares The actual thing is space but for some reason when i past to here it takes the spaces out.
rphares
@rphares
May 17 2016 03:08
oh, not quite--
spaces in the code dont count
"My" + myNoun
is Mydog
myNoun + " " + myVerb
is dog ran
OneRandomJamie
@OneRandomJamie
May 17 2016 03:09
ok
rphares
@rphares
May 17 2016 03:09
gives those a go, and feel free to come back if stuck!
(I'm going to bed soon, though-- good luck and happy coding~ )
OneRandomJamie
@OneRandomJamie
May 17 2016 03:09
@rphares thank you again
CamperBot
@camperbot
May 17 2016 03:09
onerandomjamie sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:warning: onerandomjamie already gave rphares points
rphares
@rphares
May 17 2016 03:10
Anytime~
OneRandomJamie
@OneRandomJamie
May 17 2016 03:10
@rphares Good night
sbc4242
@sbc4242
May 17 2016 03:27

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

// Only change code below this line
function updateRecords(id, prop, value) {
if(value!=="" && prop!=="tracks")
{
collection.id.prop=value;
}
else if(prop==="tracks" && value!==""){
collection.id.prop.push(value);
}
else if(value===""){
delete collection.id.prop;
}

return collection;
}

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

this code keep saying that : TypeError: Cannot set property 'prop' of undefined
can anyone help me out
coekwaawu
@coekwaawu
May 17 2016 03:29
Try to use collection[id][prop]
sbc4242
@sbc4242
May 17 2016 03:30
Thanks you so much. It worked out well
but is there any difference between dot and bracket
rphares
@rphares
May 17 2016 03:34
im not good at explaining it, but that article helped me. (yes, there is a difference in when we can use them....)
coekwaawu
@coekwaawu
May 17 2016 03:38
I don't know why,I just do what the note says:Don't forget to use bracket notation when accessing object properties with variables.
Keenen Garnett
@Wallyw4
May 17 2016 03:39

i need some help i m doing everything it wants it returns 2 and removes the first and adds item to the last
function nextInLine(arr, item) {
arr.shift(arr);
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, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

estnimbus
@estnimbus
May 17 2016 03:39
hello guys . iam stuck at "Stand in Line"
Keenen Garnett
@Wallyw4
May 17 2016 03:39
me @estevenimbus
too @estevenimbus
estnimbus
@estnimbus
May 17 2016 03:39
@Wallyw4
Travis
@dukenukethem
May 17 2016 03:39
The person who wrote https://medium.com/@prufrock123/js-dot-notation-vs-bracket-notation-797c4e34f01d#.5a8x33pc1 is HIGHLY biased against cats; like dang
Daniel Robinson
@danielrob
May 17 2016 03:40
Just finished the US phone numbers one, but wondering how short people have managed to get it?
estnimbus
@estnimbus
May 17 2016 03:40
Lets try and figure it out @Wallyw4
Keenen Garnett
@Wallyw4
May 17 2016 03:40
ok @estevenimbus
Travis
@dukenukethem
May 17 2016 03:40
@danielrob validate US Telephone numberS?
Daniel Robinson
@danielrob
May 17 2016 03:40
@dukenukethem Yep that's it :)
Travis
@dukenukethem
May 17 2016 03:41
Oh okay; I'm nowhere near it haha
Daniel Robinson
@danielrob
May 17 2016 03:41
oh haha :)
Keenen Garnett
@Wallyw4
May 17 2016 03:41
so this is my output: Before: [1,2,3,4,5,]
2
After: [2,3,4,5,6]
is that not what they wanted?
Travis
@dukenukethem
May 17 2016 03:42
Looks like you need to have a firm grasp on RegEx to get that challenge done
Keenen Garnett
@Wallyw4
May 17 2016 03:43
??
Daniel Robinson
@danielrob
May 17 2016 03:43
@dukenukethem yeah. It took me three searches, & then I used two chained replaces for the final check, I imagine it can be done in less.
In saying that it's a readable solution which counts for something.
Keenen Garnett
@Wallyw4
May 17 2016 03:44
I wonder what im missing
estnimbus
@estnimbus
May 17 2016 03:44
@Wallyw4 yes i try different things
and I get only 2 out of the 4 checked right
Keenen Garnett
@Wallyw4
May 17 2016 03:45
yup same here @estevenimbus
buiphuking
@buiphuking
May 17 2016 03:45
can we change font-family for number , guys ?
estnimbus
@estnimbus
May 17 2016 03:46
the answer swap when i change the return part
Keenen Garnett
@Wallyw4
May 17 2016 03:46
mine havent changed what did you change in return?
estnimbus
@estnimbus
May 17 2016 03:46
@Wallyw4 what do you have on the "return item" part
i tried this
Keenen Garnett
@Wallyw4
May 17 2016 03:47
return arr[0]
estnimbus
@estnimbus
May 17 2016 03:47
@Wallyw4 return arr[0]+1
try it and see what happens
Keenen Garnett
@Wallyw4
May 17 2016 03:49
ya i got second check mark now
Daniel Robinson
@danielrob
May 17 2016 03:49
@Wallyw4 you don't need to pass the array to arr.shift()
coekwaawu
@coekwaawu
May 17 2016 03:50
Hello everyone,in challenges "Generate Random Whole Numbers within a Range",why my answer "return myMax-Math.floor(Math.random()*(myMax-myMin+1));" is wrong?
Daniel Robinson
@danielrob
May 17 2016 03:50
Also note that Array.prototype.shift changes the array.
(and returns a value)
Keenen Garnett
@Wallyw4
May 17 2016 03:50
then how do we replace the first element? @danielrob
Daniel Robinson
@danielrob
May 17 2016 03:50
Re-read the question. It's not asking you to replace the first element :)
Keenen Garnett
@Wallyw4
May 17 2016 03:51
do we decrement it?
estnimbus
@estnimbus
May 17 2016 03:51
@danielrob uhhhh ok
Keenen Garnett
@Wallyw4
May 17 2016 03:51
oh it says to remove it
Daniel Robinson
@danielrob
May 17 2016 03:51
:)
estnimbus
@estnimbus
May 17 2016 03:51
yes
Ross
@Woodywoodruff3
May 17 2016 03:51
I am stuck on Challenge 146.
i need to write this out
estnimbus
@estnimbus
May 17 2016 03:52
I still dont get the last line we are suppose to have right
@danielrob nextInLine(testArr, 10), testArr[4] should be 10
Ross
@Woodywoodruff3
May 17 2016 03:52
Set remainder equal to the remainder of 11 divided by 3 using the remainder (%) operator.
The value of remainder should be 2
Keenen Garnett
@Wallyw4
May 17 2016 03:52
i got 3 checks @estevenimbus
estnimbus
@estnimbus
May 17 2016 03:52
me too @Wallyw4
@Wallyw4 @danielrob I honestly do not evenn understand why nextInLine(testArr, 10), testArr[4] should be 10
Keenen Garnett
@Wallyw4
May 17 2016 03:54
it wants us to increase the arr index so that the next in line keeps going so index 4 would be 10 but i dont get how iwe should increment the index
Daniel Robinson
@danielrob
May 17 2016 03:54
I'm not sure how the test is implemented, testArr is probably an internal test array e.g. [1,1,1,1,1,10]
[0,1,2,3,4,10] is easier ;D
(it's not the testArray in the main code, because I have it passing, and I've changed testArr in the code to [6])
estnimbus
@estnimbus
May 17 2016 03:57
@danielrob we should report a bug then
@also why dont we have to use switch
@danielrob
Daniel Robinson
@danielrob
May 17 2016 03:57
It's not a bug, but it is slightly confusing (the code works, the test description is just confusing)
@estevenimbus what's your code so far?
estnimbus
@estnimbus
May 17 2016 03:58

function nextInLine(arr, item) {
arr.push(item);

return arr[0]; // Change this line
}

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

Daniel Robinson
@danielrob
May 17 2016 03:58
Think about how the array will be affected. E.g. [1,2,3] -> [2,3,<call value>].
Ok good, so you have [1,2,3] -> [1,2,3, item ] now you need [1,2,3,item] -> [2,3,item]. So you need to remove the first item from the array after the push.
Keenen Garnett
@Wallyw4
May 17 2016 04:00
so shift it out?
Daniel Robinson
@danielrob
May 17 2016 04:00
Does it work? ;P
coekwaawu
@coekwaawu
May 17 2016 04:00
@Woodywoodruff3 How about trying this answer in 146:"var remainder = 11 %3 "
Keenen Garnett
@Wallyw4
May 17 2016 04:01

i tried this and still nothing

function nextInLine(arr, item) {

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

return arr[0]; // Change this line
}

Daniel Robinson
@danielrob
May 17 2016 04:03
buiphuking
@buiphuking
May 17 2016 04:03
plz someone test my thing
why 10 2 = 20, but 80 2 = nothing?
http://codepen.io/buiphuking/pen/qZwpjE/?editors=0010
Daniel Robinson
@danielrob
May 17 2016 04:04
"The shift() method removes the first element from an array and returns that element. "
Islam Ibakaev
@dagman
May 17 2016 04:04
@Wallyw4 maybe u want to return arr.shift(arr[0]);
Daniel Robinson
@danielrob
May 17 2016 04:04
@dagman That would work, but it would still not be correct :D
(I consider passing parameters to functions that don't take parameters incorrect)
Keenen Garnett
@Wallyw4
May 17 2016 04:05
i go it
Daniel Robinson
@danielrob
May 17 2016 04:05
!!!!
Keenen Garnett
@Wallyw4
May 17 2016 04:05

function nextInLine(arr, item) {

arr.push(item);

return arr.shift(); // Change this line
}

Daniel Robinson
@danielrob
May 17 2016 04:05
wooot!
Keenen Garnett
@Wallyw4
May 17 2016 04:06
so what it was looking for was returning the element removed from the beginning of the array
Daniel Robinson
@danielrob
May 17 2016 04:07
Yep: "The nextInLine function should then return the element that was removed." :)
Good work. There is also .unshift() for putting an element back on the front of an array
Keenen Garnett
@Wallyw4
May 17 2016 04:08
so return will actually execute the code and return the outcome of said execution?
Daniel Robinson
@danielrob
May 17 2016 04:08
and .pop() for removing an element from the end
Ross
@Woodywoodruff3
May 17 2016 04:11
@coekwaawu Thanks! I could have sworn I wrote that code. I was pulling my hair out.
CamperBot
@camperbot
May 17 2016 04:11
woodywoodruff3 sends brownie points to @coekwaawu :sparkles: :thumbsup: :sparkles:
Keenen Garnett
@Wallyw4
May 17 2016 04:12
how do i send you brownies? @danielrob
Daniel Robinson
@danielrob
May 17 2016 04:12
Oh, cheers, I think like thanks @Wallyw4
CamperBot
@camperbot
May 17 2016 04:12
danielrob sends brownie points to @wallyw4 :sparkles: :thumbsup: :sparkles:
Daniel Robinson
@danielrob
May 17 2016 04:12
(just include the word t.hanks)
Keenen Garnett
@Wallyw4
May 17 2016 04:13
thanks @danielrob
CamperBot
@camperbot
May 17 2016 04:13
wallyw4 sends brownie points to @danielrob :sparkles: :thumbsup: :sparkles:
Keenen Garnett
@Wallyw4
May 17 2016 04:13
woo
Daniel Robinson
@danielrob
May 17 2016 04:14
All good @estevenimbus ?
Samuel Cupidon
@Zerazera
May 17 2016 04:17
@buiphuking You have a space with your 8
Kelly Kovalcik
@kellykov
May 17 2016 04:19
For Converting Celsius to Fahrenheit - you have to write out the correct words in the formula. So the answer should be:
var fahrenheit = 9/5 * celsius + 32
estnimbus
@estnimbus
May 17 2016 04:25
Yes! Thank you @danielrob
CamperBot
@camperbot
May 17 2016 04:25
estevenimbus sends brownie points to @danielrob :sparkles: :thumbsup: :sparkles:
estnimbus
@estnimbus
May 17 2016 04:25
@Wallyw4 how far are you going to be studying this
??
today
Keenen Garnett
@Wallyw4
May 17 2016 04:26
I'm going to bed now lol
estnimbus
@estnimbus
May 17 2016 04:27
same
man
I have to be up in 5 hours
but you want to google hang out
Keenen Garnett
@Wallyw4
May 17 2016 04:27
I have to be up in 6
estnimbus
@estnimbus
May 17 2016 04:27
and work on this tomorrow?
Keenen Garnett
@Wallyw4
May 17 2016 04:28
The whole javascript map? Or just that one thing?
estnimbus
@estnimbus
May 17 2016 04:28
I like to have somebody at the same level as me so I can check my progress and not fall behind
buiphuking
@buiphuking
May 17 2016 04:28
@Zerazera
estnimbus
@estnimbus
May 17 2016 04:29
depends how much do you work on this per week , ? day?
@Wallyw4
Keenen Garnett
@Wallyw4
May 17 2016 04:29
Idk just when I can I'm also in the process of buying my first house so its hard to find time
estnimbus
@estnimbus
May 17 2016 04:30
ok no worries then
good luck with the house
see you again sometimes
Keenen Garnett
@Wallyw4
May 17 2016 04:30
Have a good night man n thanks @estevenimbus
CamperBot
@camperbot
May 17 2016 04:30
wallyw4 sends brownie points to @estevenimbus :sparkles: :thumbsup: :sparkles:
estnimbus
@estnimbus
May 17 2016 04:31
@Wallyw4 thanks
CamperBot
@camperbot
May 17 2016 04:31
estevenimbus sends brownie points to @wallyw4 :sparkles: :thumbsup: :sparkles:
Arvilyn Ong
@arvilyn
May 17 2016 04:32
hi , i'm stuck at 'Return Largest Numbers in Arrays', could anyone tell me what's wrong with my code?
function largestOfFour(arr) {
// You can do this!
var newArr = [];
var largest = 0;
for(var i=0; i < arr.length; i++) { // for each [ ],
for(var j =0 ; j < arr[i].length; j++) { //for each element inside [],
if (arr[i][j] > largest) {
largest = arr[i][j];
} else {
return largest;
}
}
return newArr.push(largest);
}
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Coy Sanders
@coymeetsworld
May 17 2016 04:33
return largest
you don't want that in there @arvilyn
it will exit your function prematurely
also you will want to reset your largest variable in a different location
Lemmy
@imnotlammy
May 17 2016 04:34
        $(".container").click(function() { if($(".temperature").has(tempC)) {
$(".temperature").html(tempF + "Β°F"); } else {$(".temperature").html(tempC + "Β°C");
}
});
hi all
Coy Sanders
@coymeetsworld
May 17 2016 04:34
and don't want to return newArr.push(largest), you want to do that separately, then return newArr when you're done with both loops, so quite a bit :)
Lemmy
@imnotlammy
May 17 2016 04:34
how do I get the temperature to toggle between celcius and farenheit on click?
Coy Sanders
@coymeetsworld
May 17 2016 04:37
not familiar with has() function @imnotlammy, but i'm not sure if it searches like that, only grabs tags, could be wrong
I would add some console.log lines at various places in your code and try debugging that way
see what happens when your click function runs, and if it runs for one
Lemmy
@imnotlammy
May 17 2016 04:37
@coymeetsworld the function only works when converting from C to F
but I can't get it to switch back
SuryaKavutarapu
@SuryaKavutarapu
May 17 2016 04:38

js
var count = 0;

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

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

// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
 guys whats wrong with my code can anybody help

CamperBot
@camperbot
May 17 2016 04:38
:bulb: to format code use backticks!  more info
Coy Sanders
@coymeetsworld
May 17 2016 04:38
can you show the rest of the code?
DJ
@qualitymanifest
May 17 2016 04:38
Lemmy
@imnotlammy
May 17 2016 04:38
DJ
@qualitymanifest
May 17 2016 04:39
@imnotlammy also i think that would be a better use for .text() instead of .html()
Coy Sanders
@coymeetsworld
May 17 2016 04:39
assuming hes not inadvertantly deleting html inside that class
that he needs to preserve
Arvilyn Ong
@arvilyn
May 17 2016 04:39
@coymeetsworld i managed to solve it, thank you so much!!! :smile:
CamperBot
@camperbot
May 17 2016 04:39
arvilyn sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
Coy Sanders
@coymeetsworld
May 17 2016 04:39
nice @arvilyn :thumbsup: congrats i know there was a bit I said lol
Lemmy
@imnotlammy
May 17 2016 04:40
weird, why is it displaying blank?
Does it have something to do with the API?
Coy Sanders
@coymeetsworld
May 17 2016 04:40
idk @imnotlammy, are you using chrome?
Lemmy
@imnotlammy
May 17 2016 04:40
yeah
Coy Sanders
@coymeetsworld
May 17 2016 04:40
because geolcation isn't supported anymore
on non-secure connections in chrome
Lemmy
@imnotlammy
May 17 2016 04:40
oic
Coy Sanders
@coymeetsworld
May 17 2016 04:40
you need another way of getting coordinates, or if you don't want to mess with that just hardcode some values for now
and then add that feature later if you want to focus on getting buttons working
oh i guess you did lol
Lemmy
@imnotlammy
May 17 2016 04:42
yeah lol
Coy Sanders
@coymeetsworld
May 17 2016 04:43
@imnotlammy im not sure why it works first time and not second because of this
but i notice your button click function is nested inside your getJSON function
you should take it outside of that
code won't be able to read that because it's nested in an anonymous function.
now why it works the first time? i'm not 100% sure
Anteli
@Anteli
May 17 2016 04:46
Hello!
DJ
@qualitymanifest
May 17 2016 04:46
it actually will work despite being inside the getJSON
i made it work by using .text() for everything rather than .has() and .html()
if temperature's text is in c, convert text to f. else convert text to c
Coy Sanders
@coymeetsworld
May 17 2016 04:47
hmm interesting @qualitymanifest
i was thinking maybe somehow after the container was clicked it lost that click action but that didn't make sense to me
Lemmy
@imnotlammy
May 17 2016 04:48
@qualitymanifest 
DJ
@qualitymanifest
May 17 2016 04:48
@coymeetsworld yeah i can understand that, that was my assumption at first
Lemmy
@imnotlammy
May 17 2016 04:48
        $(".container").click(function() { if ($(".temperature").text == tempC) {
$(".temperature").text(tempF + "Β°F"); } else {$(".temperature").text(tempC + "Β°C");
}
});
@qualitymanifest
this?
DJ
@qualitymanifest
May 17 2016 04:48
@imnotlammy it's .text() not just .text
and the text originally isn't just tempC. it's tempC + "Β°C"
so you will need to change your if
Lemmy
@imnotlammy
May 17 2016 04:49
ahh ok
I will save + "Β°C"
in the var then
should work
DJ
@qualitymanifest
May 17 2016 04:50
i didnt change the var, just used it in the comparison
Coy Sanders
@coymeetsworld
May 17 2016 04:50
or you can use the String.includes function
i think you can search for numbers, not 100% sure
Lemmy
@imnotlammy
May 17 2016 04:51
        $(".container").click(function() { if ($(".temperature").text() == tempC + "Β°C") {
$(".temperature").text(tempF + "Β°F"); } else {$(".temperature").text(tempC + "Β°C");
}
});
worked!
@qualitymanifest thanks
CamperBot
@camperbot
May 17 2016 04:51
imnotlammy sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star2: 1164 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
DJ
@qualitymanifest
May 17 2016 04:51
np
Anteli
@Anteli
May 17 2016 04:57

Hey mates! I have been been struggling with this for hours. Something strange is happening.

<!DOCTYPE html>
<html>
<body>
<script src="script.js"></script>
<p id="intro">Hello World!</p>
<p>This example demonstrates the <b>getElementById</b> method!</p>
<p id="demo"></p>
</body>
</html>

<script src="script.js"></script>

after:

<p id="demo"></p>

Then it works.

<!DOCTYPE html>
<html>
<body>
<script src="script.js"></script>
<p id="intro">Hello World!</p>
<p>This example demonstrates the <b>getElementById</b> method!</p>
<p id="demo"></p>
<script src="script.js"></script>
</body>
</html>

JavaScript:

var myElement = document.getElementById("intro");
document.getElementById("demo").innerHTML =
"The text from the intro paragraph is " + myElement.innerHTML;

Thanks for help!

Walter Augustine
@Walter-0
May 17 2016 05:00
@Anteli Your script is trying to get an html element thatβs not loaded yet
@Anteli Best practice is to put your script tags at the end of the body so youβve got it already
Diwakar Serala
@diwpro007
May 17 2016 05:04
can some one explain what this exact change challenge is trying to say?
Karthi Keyan
@mskarthi95
May 17 2016 05:04
Diwakar Serala
@diwpro007
May 17 2016 05:08
can some one explain what this Exact Challenge challenge is trying to say?
https://www.freecodecamp.com/challenges/exact-change
Darth Skywalker
May 17 2016 05:12
help exact change
CamperBot
@camperbot
May 17 2016 05:12
no wiki entry for: exact challenge
Anteli
@Anteli
May 17 2016 05:13
@Walter-0 Thanks! That explains!
CamperBot
@camperbot
May 17 2016 05:13
anteli sends brownie points to @walter-0 :sparkles: :thumbsup: :sparkles:
Anteli
@Anteli
May 17 2016 05:16
@camperbot how to do it? :)
Walter Augustine
@Walter-0
May 17 2016 05:16
help where art thou
CamperBot
@camperbot
May 17 2016 05:16

# Problem Explanation

Write an algorithm that will take an array for the first argument and return an array with all the objects that matches all the properties and values in the Object passed as second parameter.

Diwakar Serala
@diwpro007
May 17 2016 05:17
help exact change
CamperBot
@camperbot
May 17 2016 05:17

# Problem Explanation:

• You have to create a program that will handle when the register does not have
enough cash or will have no cash after the transaction. Other than that it
needs to return an array of the change in the form of an array, so that will
be a 2D array.
Greg
@GregJacoby
May 17 2016 05:27
can someone offer me a -hint- on mutations? im not quite sure where to start. as small of a hint as possible. i see they suggest using indexOf, but it's still not clicking
help mutations
CamperBot
@camperbot
May 17 2016 05:29

# Problem Explanation:

• Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array..
Markus Kiili
@Masd925
May 17 2016 05:32
@GregJacoby Pick the strings to variables and lowercase them. Loop through the second string characters and...
Greg
@GregJacoby
May 17 2016 05:32
oo okay
thanks
i'll start there
@Masd925 thank you
CamperBot
@camperbot
May 17 2016 05:33
gregjacoby sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1512 | @masd925 |http://www.freecodecamp.com/masd925
Kelly Kovalcik
@kellykov
May 17 2016 05:49
Can I have some help with "Escaping Literal Quotes in Strings" please? I'm not sure why but for some reason I've been stuck on this. This is what I've been trying. Does anyone know what I'm doing wrong?
var myStr = "I am a \"double quoted\" string inside \"double quotes\".";
Keone Martin
@Athaman
May 17 2016 05:51
there is no full stop at the end i think
@kellykov
Coy Sanders
@coymeetsworld
May 17 2016 05:53
shouldn't be a period at the end @kellykov
you escaped the quotes right
Kelly Kovalcik
@kellykov
May 17 2016 05:55
Yes thank you @Athaman @coymeetsworld
This is what it should be:
CamperBot
@camperbot
May 17 2016 05:55
kellykov sends brownie points to @athaman and @coymeetsworld :sparkles: :thumbsup: :sparkles:
Kelly Kovalcik
@kellykov
May 17 2016 05:55
var myStr = "I am a \"double quoted\" string inside \"double quotes\"";
Coy Sanders
@coymeetsworld
May 17 2016 05:55
np @kellykov :thumbsup:
Keone Martin
@Athaman
May 17 2016 05:59
you're welcome
SuryaKavutarapu
@SuryaKavutarapu
May 17 2016 06:23

guys i'm stuck over here can anybody please help js

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

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

Keone Martin
@Athaman
May 17 2016 06:23
you need to multiply each step in the middle of your for loops
so instead of product = arr[i][j]; try product *= arr[i][j];
otherwise looks good @SuryaKavutarapu
SuryaKavutarapu
@SuryaKavutarapu
May 17 2016 06:25
thank you @Athaman it worked :smile:
CamperBot
@camperbot
May 17 2016 06:25
suryakavutarapu sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
Keone Martin
@Athaman
May 17 2016 06:25
no problem bud
David Shavers
@frontEndDevv
May 17 2016 06:34
hey guys could someone point me in the right direction of the counting cards lesson in javascript?
ERWIN JOHN T. CARPIO, MD, FPCR
May 17 2016 06:34
Hello... I'm currently on the build a random quote machine project. I already have some idea how to do it. My question is where to store the json and imgLink sources? Do you suggest I use drop box and put the json files in there or does codepen have some way for me to put in a json file?
Keone Martin
@Athaman
May 17 2016 06:35
@frontEndDevv sure, you need to separate the possible use cases into logical statements with either if/else or a switch. then inside each of them you need to react accordingly, +1 to count and bet if <=6 etc.
not sure @RadEdje, you can make a JSON object inside the JS panel and access it from there right?
ERWIN JOHN T. CARPIO, MD, FPCR
May 17 2016 06:38
@Athaman Oops my bad... i forgot I could incorporate the json directly into the js panel.... so I can just refer to the var jsonObj directly right? Thanks...
CamperBot
@camperbot
May 17 2016 06:38
radedje sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
Keone Martin
@Athaman
May 17 2016 06:39
Pretty sure i've seen that done @RadEdje but I haven't actually done the websites yet so I may be wrong, give it a go and find out ;)
Jimmy Hernandez
@dismister
May 17 2016 06:39
I'm confused hwo this regular javascipt expression works... could someone explain this to me please? str = str.replace(/[^A-Za-z0-9]/g, '');
what does the material inside the backlash mean?
Keone Martin
@Athaman
May 17 2016 06:40
ok sure, my understanding of regexp is limited but those seem to be looking for any capital, lowercase, or numeric character.
the g looks for all of the matches... and the '' is an empty string to replace them with nothing.
so running that on a string should remove all alpha-numeric characters and just leave punctuation right?
David Shavers
@frontEndDevv
May 17 2016 06:41
@Athaman Thanks man
CamperBot
@camperbot
May 17 2016 06:41
frontenddevv sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
Keone Martin
@Athaman
May 17 2016 06:41
wait, that's backwards
Jimmy Hernandez
@dismister
May 17 2016 06:41
that's what I thought but it is part of the Palindrome bon fire

function palindrome(str) {

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

return str.split('').reverse().join('').toLowerCase() === str.toLowerCase();

}

palindrome("eye");

Keone Martin
@Athaman
May 17 2016 06:41
@dismister the regexp there is searhing for anything which isn't an alphanumeric character and deleting it
ERWIN JOHN T. CARPIO, MD, FPCR
May 17 2016 06:42
What about images though? I was hoping to spruce up the random quote machinewith a few cute cat images hehe... I prefer to make my own images to avoid randomly getting images from the net that might have copytights... any suggestions on a good image hosting site? Dropbox? Instagram? Or can github serve these things? (Pics and json etc).
Keone Martin
@Athaman
May 17 2016 06:42
Jimmy Hernandez
@dismister
May 17 2016 06:42
ooo that makes perfect sense @Athaman keone thank you
CamperBot
@camperbot
May 17 2016 06:42
dismister sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
Keone Martin
@Athaman
May 17 2016 06:43
@RadEdje not sure about images sorry, there are a tonne of hosting sites obviously, or you can just go to google image and steal their kittens.
Jimmy Hernandez
@dismister
May 17 2016 06:46
what about the single quotes after the g? str = str.replace(/[^A-Za-z0-9]/g, '');
what is that for?
Coy Sanders
@coymeetsworld
May 17 2016 06:46
Keone Martin
@Athaman
May 17 2016 06:46
that's what the matched characters will be replaced with, so in this case it's an empty string, or nothing, essentially just deleting the character
Coy Sanders
@coymeetsworld
May 17 2016 06:47
idk about github, if you have a url to the image possibly
didn't try seeing if i can access it into something like CodePen
Keone Martin
@Athaman
May 17 2016 06:47
so str = str.replace("a", "b"); will look for the first a and change it to a b
Jimmy Hernandez
@dismister
May 17 2016 06:48
you are a life saver @Athaman much appreciated man.
Keone Martin
@Athaman
May 17 2016 06:49
no worries my friend, always nice to help out
Krzysztof Borowy
@Krizzu
May 17 2016 06:49
Hi guys. After reading few articles on Medium I wondered
Everyone is saying to code every day
but, I think I struggle to make a progress in my learning
Keone Martin
@Athaman
May 17 2016 06:51
things take time sometimes
Krzysztof Borowy
@Krizzu
May 17 2016 06:51
I'm confortable with JS, I created intermediate project with ease, JQuery is not a problem
Keone Martin
@Athaman
May 17 2016 06:55
what are you having troubles with?
Krzysztof Borowy
@Krizzu
May 17 2016 06:55
I think I just don't feel like doing any progress
I would love to know what I should know before learning like bigger stuff, like react or nodejs
because now I feel like if I start them, I will fail
May 17 2016 06:57
@Krizzu Coding is a journey and not a race.
I would recommend to start off with the basics: HTML & CSS
then work your way up to basic javascript.
Krzysztof Borowy
@Krizzu
May 17 2016 06:58
@dadams-510 I've got it, more then a basics
But now I struggle if I should move forward or work on somethig else
Keone Martin
@Athaman
May 17 2016 06:58
honestly at the moment i'm going sort of gung ho on it. i'm starting random courses and trying random things and half of them are completely beyond my abilites so i just switch it up and will come back to it later... it's not like it's a terrible thing to not be able to handle advanced things at the moment, and unfortunately with coding there is no clear road map for what comes next on a scale of challenge. some people find some things easy and struggle on other things that i may find easy. you just need to try stuff, find out what you enjoy, and work at it.
Krzysztof Borowy
@Krizzu
May 17 2016 06:59
@Athaman That's an actualy a fantastic advice, thanks
CamperBot
@camperbot
May 17 2016 06:59
krizzu sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
Krzysztof Borowy
@Krizzu
May 17 2016 07:00
I think I will stick to getting my Certificate at FCC, doing react/nodejs meanwhile
Keone Martin
@Athaman
May 17 2016 07:00
sounds good
Alexandr
@alexakuna
May 17 2016 07:09
"Golf Code"
Kyle W Pilkinton
May 17 2016 07:10
hey guys how would i filter out all variables in the filter array out of the data array in this code?
function diffArray(arr1, arr2) {
var newarr = [];
var filter = [];
var filtered = [];
// Same, same; but different.

for(var i = 0 ; i < arr1.length; i++){
for(var j = 0; j < arr2.length; j++){

if(arr1[i] == arr2[j]){

filter[i] = arr1[i];

}
}
}

var data = arr1.concat(arr2);

}
return newarr;
}
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
May 17 2016 07:10
need help with Counting cards

var count = 0;

function cc(card) {
// Only change code below this line
for(i=0;i<card.length;i++)
{
if(card[i]==10 || card[i]=='J' || card[i]=='Q' || card[i]=='K' || card[i]=='A')
count--;
else if(card[i]==2 || card[i]==3 || card[i]==4 || card[i]==5 || card[i]==6)
count++;

}

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

Spartano
@Spartano
May 17 2016 07:11
someone can explain me why (\w)\1{1} selects all word charcther that repeats itself 2 times, i dont get why i put {1} and not {2}... thanks
Keone Martin
@Athaman
May 17 2016 07:11
@tadake filter works by saying array.filter() and you need to put stuff in the brackets, i'd suggest googling filter() JS and reading an article on it
Markus Kiili
@Masd925
May 17 2016 07:11
@tadake You wan't to filter out elements of one array if they exist in the second array?
Keone Martin
@Athaman
May 17 2016 07:11
@alexakuna what do you need for golf code?
Kyle W Pilkinton
May 17 2016 07:12
ive tried reading about it online but im having difficulties understanding @Athaman
yeah that what im trying to do @Masd925
Alexandr
@alexakuna
May 17 2016 07:12
I can not understand
Keone Martin
@Athaman
May 17 2016 07:12
@vjadon in counting cards you're getting passed 1 number each time and being called multiple times, so you don't need to access any arrays.
May 17 2016 07:13
it doesnt work this way too

var count = 0;

function cc(card) {
// Only change code below this line
if(card==10 || card=='J' || card=='Q' || card=='K' || card=='A')
count--;
else if(card==2 || card==3 || card==4 || card==5 || card==6)
count++;

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

Keone Martin
@Athaman
May 17 2016 07:14
that code looks much closer @vjadon
May 17 2016 07:14
ok
Markus Kiili
@Masd925
May 17 2016 07:14
var arr1 = [1,2,3,4,5,6];
var arr2 = [2,4];
var filtered = arr1.filter(function (elem) {  // [1,3,5,6]
return arr2.indexOf(elem)===-1;
});
Keone Martin
@Athaman
May 17 2016 07:15
but you have hold and bet backwards @vjadon
if count > 0 you should return count + " Bet";
May 17 2016 07:16
such a silly mistake
thanx @Athaman
CamperBot
@camperbot
May 17 2016 07:16
vjadon sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
Keone Martin
@Athaman
May 17 2016 07:16
@alexakuna you just need to set up a bunch of if/else (or a switch) statements that screen out the different golf scores
@vjadon happens to the best of us ;)
Alexandr
@alexakuna
May 17 2016 07:18
ΠΎΠΊ
Keone Martin
@Athaman
May 17 2016 07:19
then if(strokes -par <-2){//make your function return "Eagle"} and work your way up
Kyle W Pilkinton
May 17 2016 07:21
im working on the diff two arrays challenge and i used that function and im still not getting the correct output. is there any error in this updated code @Masd925
function diffArray(arr1, arr2) {
var newarr = [];
var filter = [];
var filtered = [];
// Same, same; but different.

for(var i = 0 ; i < arr1.length; i++){
for(var j = 0; j < arr2.length; j++){

if(arr1[i] == arr2[j]){

filter[i] = arr1[i];

}
}
}

var data = arr1.concat(arr2);

filtered = arr1.filter(function (elem) {
return arr2.indexOf(elem) === -1;
});

return filtered;

}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Keone Martin
@Athaman
May 17 2016 07:23
@tadake your whole first loops logic is a little wonky, at the moment you're running through all the elements in arr2 by using j then saving those that match to filter[i] but i doesn't increment til the end of the j loop, so you'll keep overwriting filter[0] for any matches between the first element of arr1 and any element in array 2
PcbcN
@PcbcN
May 17 2016 07:24
Hi everyone, I'm stuck in the "Return Largest Numbers in Arrays" exercise. I've written some code that I think should work (iterate array + iterate subarray + compare with empty results array + define result) but it keeps returning myArr [0,0,0,0]. My code is:
function largestOfFour(arr) {
var myArr = [0,0,0,0];

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

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

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

}

}

}

return myArr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Markus Kiili
@Masd925
May 17 2016 07:25
@tadake You could use the filter function to first filter out elements of arr2 from arr1 and then elements of arr1 from arrr2. Concating those two result arrays should give the answer.
Keone Martin
@Athaman
May 17 2016 07:27
@PcbcN you are missing a g in arr.lenth --> should be arr.length;
which may prevent the loop from running at all since i don't think that would evaluate to true
Kyle W Pilkinton
May 17 2016 07:29
thanks Markus @Masd925 im having trouble understanding the logic behind the call back function using .filter .
CamperBot
@camperbot
May 17 2016 07:29
tadake sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1513 | @masd925 |http://www.freecodecamp.com/masd925
PcbcN
@PcbcN
May 17 2016 07:29
@Athaman Thanks a lot!
CamperBot
@camperbot
May 17 2016 07:29
pcbcn sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
Keone Martin
@Athaman
May 17 2016 07:30
no problem :)
Markus Kiili
@Masd925
May 17 2016 07:30
@tadake The callback tells filter how to filter one arbitrary array element elem. If the return value from callback is true, the element is kept. The filter method iterates array elements automatically under the hood and passes each element to the callback you provide.
cnj1987
@cnj1987
May 17 2016 07:32
Can someone tell me if I've done this wrong?
Manipulate Arrays With pop
I just typed in the array and passed... :D
Keone Martin
@Athaman
May 17 2016 07:33
sure, we can look over some code
cnj1987
@cnj1987
May 17 2016 07:33
code var removedFromMyArray = ["cat", 2];
Kyle W Pilkinton
May 17 2016 07:34
is this sorta what i should be shooting for @Masd925 ??
 filter = arr2.filter(function(arr1){

return arr1 !== arr2;

});
cnj1987
@cnj1987
May 17 2016 07:34
But the instructions were: Use the .pop() function to remove the last item from myArray, assigning the "popped off" value to removedFromMyArray.
Keone Martin
@Athaman
May 17 2016 07:34
riiight, yeah, no that's not what you're looking to do there @cnj1987
cnj1987
@cnj1987
May 17 2016 07:34
I thought so, which is why I came back to it, lol
Keone Martin
@Athaman
May 17 2016 07:35
so you've changed the code above the do not change the code above this line right?
cnj1987
@cnj1987
May 17 2016 07:35
Yeah
Keone Martin
@Athaman
May 17 2016 07:35
set it back to the default because you'll need the original for the proper solution to work
cnj1987
@cnj1987
May 17 2016 07:35
var removedFromMyArray = ["cat", 2].pop(); == When I use this, I only get 2 in the array; not "cat".
Markus Kiili
@Masd925
May 17 2016 07:35
@tadake The parameter of filter callback is the array element being iterated. elem is a good name for the parameter.
cnj1987
@cnj1987
May 17 2016 07:35
Done
Keone Martin
@Athaman
May 17 2016 07:36
ok, so if you .pop() myArray without changing it you should get back [cat, 2]
["cat", 2]*
Markus Kiili
@Masd925
May 17 2016 07:36
@tadake This was the way to filter array elements from another array:
var filtered = arr1.filter(function (elem) {  // [1,3,5,6]
return arr2.indexOf(elem)===-1;
});
cnj1987
@cnj1987
May 17 2016 07:36
AH!
var removedFromMyArray = myArray.pop();
??
Keone Martin
@Athaman
May 17 2016 07:36
so if you have removedFromMyArray = myArray.pop(); you will get exactly the same result as you have manually done
yeah that's the one
cnj1987
@cnj1987
May 17 2016 07:36
There we go :D
So it takes an array as a whole with pop()?
Keone Martin
@Athaman
May 17 2016 07:37
and what that does is what you did manually, it takes the last element of an array, in this case ["cat", 2] out of the array
and saves it if you have a var variable = on the left
cnj1987
@cnj1987
May 17 2016 07:37
Awesome :)
Keone Martin
@Athaman
May 17 2016 07:37
otherwise it just deletes it permanently
so if you say
myArray.pop() // this will just delete the last element, never to be seen again
cnj1987
@cnj1987
May 17 2016 07:38
That made the next one work perfectly as well (myArray.shift(); )
Keone Martin
@Athaman
May 17 2016 07:38
yup
cnj1987
@cnj1987
May 17 2016 07:38
Thanks @Athaman
CamperBot
@camperbot
May 17 2016 07:38
cnj1987 sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
Keone Martin
@Athaman
May 17 2016 07:38
so they're basically the same thing but shift() is the front of the array and pop() is the back
similarly you can use unshift(something) to put something at the front of and array and push(something) to put something on the back
no problem :)
cnj1987
@cnj1987
May 17 2016 07:39
I just got to use unshift :D
It was the syntax I seemed to be struglging with. I'm still suffering with cluelessness with JS
Keone Martin
@Athaman
May 17 2016 07:40
that's reasonable, feel free to come back here if you have any issues.
Kyle W Pilkinton
May 17 2016 07:40
ahh it finnaly clicked @Masd925 !!! thank you !
CamperBot
@camperbot
May 17 2016 07:40
tadake sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
Keone Martin
@Athaman
May 17 2016 07:40
google also helps but sometimes the example is just as confusing
cnj1987
@cnj1987
May 17 2016 07:40
Yeah, I've found that a fair bit
Zurab Iashvili
@electronx
May 17 2016 07:40
does anyone else feel like punching the laptop?
cnj1987
@cnj1987
May 17 2016 07:40
Sometimes I end up on, say, Stackoverflow, and the solution is more complex
Keone Martin
@Athaman
May 17 2016 07:41
use it as your first resource, because you'll always need to check syntax things and google is quicker than people... but if it doesn't help then come here and someone can normally explain
cnj1987
@cnj1987
May 17 2016 07:41
Will do :)
Keone Martin
@Athaman
May 17 2016 07:41
stackoverflow is an art in and of itself, you need to learn how to ignore alllll the crazy stuff and just look for the line that looks like it will fit in your code ;)
cnj1987
@cnj1987
May 17 2016 07:41
Sounds like a plan :D
Keone Martin
@Athaman
May 17 2016 07:41
@electronx i like my laptop, it keeps me entertained.
but things do get frustrating sometimes. it's worth taking a break sometimes, when the coding isn't fun and just annoying then you end up spiralling down and just hating it.
Zurab Iashvili
@electronx
May 17 2016 07:42
@Athaman yes but some problems are so hard, its very tempting to put a hole on screen :D
Keone Martin
@Athaman
May 17 2016 07:43
need any advice on a specific problem or just venting?
Dan Couper
@DanCouper
May 17 2016 07:48
var arr1 = [1, 2, 3, 4]
var arr2 = [6, 7, 2, 4]
// so
arr1.filter(function(elem) { return arr2.indexOf(elem) === -1 })
// filter is going to give you back a new array that consistes of every value that the
// callback returns true for. The callback takes the current value of the array, and moves
// left -> right until it hits the end.
// first element of arr1 is 1
function(1) { return arr2.indexOf(1) === -1 } // true: 1 is not in arr2, it has an index of -1
// second element of arr1 is 2
function(2) { return arr2.indexOf(2) === -1 } // false: 2 is in arr2, it has an index of 2
// third element of arr1 is 3
function(3) { return arr2.indexOf(3) === -1 } // true: 3 is not in arr2, it has an index of -1
// fourth element of arr1 is 4
function(4) { return arr2.indexOf(4) === -1 } // false: 4 is not in arr2, it has an index of 3
// so returns:
[1,4]
cnj1987
@cnj1987
May 17 2016 07:48
I think I've got this right --
1. Create a function called reusableFunction which prints "Hi World" to the dev console.
2. Call the function.
function reusableFunction() {
console.log("Hi World");
}
Keone Martin
@Athaman
May 17 2016 07:49
yup that looks right @cnj1987

but you need to call the function, so have you got the line

reusableFunction();

underneath it?

cnj1987
@cnj1987
May 17 2016 07:51
I didn't have to when I entered it -- but yeah, I would've put it if I'd not clicked next :D
(I have an unusual ability to accidentally break everything)
Keone Martin
@Athaman
May 17 2016 07:51
haha that's a little strange, but they call it in their example so maybe that does it
you know how to call functions though? cos that's important moving forward
cnj1987
@cnj1987
May 17 2016 07:52
Just write its name and the arguments involved if required, right?
Keone Martin
@Athaman
May 17 2016 07:52
pretty much yeah
and you get that conceptually that just calls the chunk of code that you've written already
cnj1987
@cnj1987
May 17 2016 07:52

e.g.,

function functionThing(a * b);
functionThing(2, 10);

??

with {}, whoops
Keone Martin
@Athaman
May 17 2016 07:53
yeah, although you shouldn't call your function functionThing
cnj1987
@cnj1987
May 17 2016 07:53
Not very descriptive.. :D
Lemmy
@imnotlammy
May 17 2016 07:53
can someone help me with global variables?
Darth Skywalker
May 17 2016 07:57
@imnotlammy : Whats the problem? You had forgot to include jQuery in your pen :)
Lemmy
@imnotlammy
May 17 2016 07:57
@adityaparab I can't save the values from JSON to global var

$(document).ready(function() { //LOCATION var city; var country;$.getJSON('http://ipinfo.io', function(data) {
city = data.city;
country = data.country;
console.log(country); //THIS DOES NOT RETURN UNDEFINED
})

console.log(country); //RETURNS UNDEFINED

});

Darth Skywalker
May 17 2016 07:58
your data is not a global variable.
Lemmy
@imnotlammy
May 17 2016 07:58
is there a way to save the value outside the .getJSON function?
Coy Sanders
@coymeetsworld
May 17 2016 07:59
yes @imnotlammy, but have to be careful doing that
since getJSON is asynchronous call, that variable may not be populated before running other parts of your code, and if you need that variable elsewhere it may not be guaranteed to come
thats why your 2nd console.log function returns undefined, although it won't always do that necessarily
Darth Skywalker
May 17 2016 08:01

@imnotlammy : Yes. That is a common mistake people make while learning async programming.

Your $.getJSON is an asynchronous call. That means, when you make $.getJSON call, it will make api call. It won't suspend until the API responds. It will, instead continue with next statements.

So by the time API responds, your console.log(country) will be executed. And it is undefined'. You set value ofcountry AFTER API responds. :)

Lemmy
@imnotlammy
May 17 2016 08:01
is it better to nest everything inside the getJSON then?
Coy Sanders
@coymeetsworld
May 17 2016 08:01
for things you need to reply on data from an API call, yes
Darth Skywalker
May 17 2016 08:02

@imnotlammy

is it better to nest everything inside the getJSON then?

It is a correct way, but not better. You should learn about a design pattern called Promise.

Lemmy
@imnotlammy
May 17 2016 08:04
hmm
this is for the local weather challenge
anyways
CamperBot
@camperbot
May 17 2016 08:06
imnotlammy sends brownie points to @coymeetsworld and @adityaparab :sparkles: :thumbsup: :sparkles:
Coy Sanders
@coymeetsworld
May 17 2016 08:06
np @imnotlammy
does that work for you?
Chris Wilson
@blockbeard
May 17 2016 08:18
help where art thou
CamperBot
@camperbot
May 17 2016 08:18

# Problem Explanation

Write an algorithm that will take an array for the first argument and return an array with all the objects that matches all the properties and values in the Object passed as second parameter.

Chris Cullen
@123xylem
May 17 2016 08:22
http://codepen.io/123xylem/pen/aNxREJ?editors=1011 Can some1 advise me why my search is unresponsive?
Ujjwal Sharma
@ryzokuken
May 17 2016 08:25
guys
there seems to be some sort of error on my challenge
the function returns the correct value, but the result is still crossed out
Keone Martin
@Athaman
May 17 2016 08:26
which challenge?
and can you send your code?
Ujjwal Sharma
@ryzokuken
May 17 2016 08:26
sure
a sec
CamperBot
@camperbot
May 17 2016 08:27

# Problem Explanation:

• This task requires us to look at each possible permutation of a string. This is best done using a recursion function. Being able to build a function which collects all permutations of a string is a common interview question, so there is no shortage of tutorials out there on how to do this, in many different code languages.
• This task can still be daunting even after watching a tutorial. You will want to send each new use of the function 3 inputs: 1. a new string (or character array) that is being built, 2. a position in your new string that's going to be filled next, and 3. an idea of what characters (more specifically positions) from the original string have yet to be used. The pseudo code will look something like this:


var str = ???;
perm(current position in original string, what's been used in original string, current string build thus far){
if(current string is finished) {
print current string;
}else{
for(var i = 0; i < str.length; i++) {

if(str[i] has not been used) {
put str[i] into the current position;
mark str[i] as used
perm(current position in original string, what's been used in original string, current string build thus far)
unmark str[i] as used because another branch in the tree for i + 1 will still likely use it;
}
Ujjwal Sharma
@ryzokuken
May 17 2016 08:27
this challenge
and here's my code
var permArr = [], usedChars = [];
var rxp = /(\w)\1/;

function permute(input) {
var i, ch;
for (i = 0; i < input.length; i++) {
ch = input.splice(i, 1)[0];
usedChars.push(ch);
if (input.length === 0) {
permArr.push(usedChars.slice());
}
permute(input);
input.splice(i, 0, ch);
usedChars.pop();
}
return permArr;
}

function permAlone(str) {
var array = permute(str.split(''));
array = array.map(function(value) {
return value.join('');
});

var num = 0;
for (var j = 0; j < array.length; j++) {
if (!rxp.test(array[j])) num++;

}
return num;
}

permAlone('aabb');
Keone Martin
@Athaman
May 17 2016 08:28
oh, I haven't done the advanced yet >.> give me a second
what's the error?
Ujjwal Sharma
@ryzokuken
May 17 2016 08:30
anybody?
Coy Sanders
@coymeetsworld
May 17 2016 08:31
ya @imnotlammy
Dan Couper
@DanCouper
May 17 2016 08:31
@ryzokuken why have you got the value.join?
Coy Sanders
@coymeetsworld
May 17 2016 08:31
may want to have your code change the cursor when you enter the box to indicate it can be clicked
Ujjwal Sharma
@ryzokuken
May 17 2016 08:32
@DanCouper i have replaced arrays with a string
Dan Couper
@DanCouper
May 17 2016 08:32
@ryzokuken ohh, I just saw that
keep it as an array, don;t use a regex
Ujjwal Sharma
@ryzokuken
May 17 2016 08:33
why not?
Dan Couper
@DanCouper
May 17 2016 08:33
itβs easier to check if the array contains consecutive values
Ujjwal Sharma
@ryzokuken
May 17 2016 08:33
the results are all correct
idk why the IDE isn't accepting
Dan Couper
@DanCouper
May 17 2016 08:33
Ah, I got an error
Ujjwal Sharma
@ryzokuken
May 17 2016 08:33
which?
Dan Couper
@DanCouper
May 17 2016 08:33
2 secs
Ujjwal Sharma
@ryzokuken
May 17 2016 08:34
here
Eldar TinjiΔ
@EldarT90
May 17 2016 08:35
can some1 look at the commented part in js
and tell me what would be the problem
Dan Couper
@DanCouper
May 17 2016 08:37
@ryzokuken huh, I get everything passing
Ujjwal Sharma
@ryzokuken
May 17 2016 08:37
why don't i?
Dan Couper
@DanCouper
May 17 2016 08:37
hmmm
Ujjwal Sharma
@ryzokuken
May 17 2016 08:37
the results are alright
fcc is not responding
not accepting them
idk why
Keone Martin
@Athaman
May 17 2016 08:38
have you tried refreshing the page?
Dany Din
@danydin
May 17 2016 08:38
function palindrome(str) {
return str.replace(/[\W_]/g, '').toLowerCase() ===
str.replace(/[\W_]/g, '').toLowerCase().split('').reverse().join('');
}
hello, why it's needed twice? return str.replace(/[\W_]/g, '').toLowerCase()
Ujjwal Sharma
@ryzokuken
May 17 2016 08:38
@Athaman and resetting my code
Lizzy
@DevElisabeth
May 17 2016 08:38
Hi all! Could someone please send me their answer to Using Objects for Lookups? I know I am really close.
Keone Martin
@Athaman
May 17 2016 08:38
strange, try a different browser? i don't actually know sorry
@danydin the first one is the string in all lower case with no symbols, the second one is the string in all lower case with no symbols backwards. so if they equal each other then it is a palindrome
@veganlizzy how about you paste your code here and we can help advise you. it's better for learning than getting the answer sent
ruchi125
@ruchi125
May 17 2016 08:40
hey guys i am having some problems with this code, looks like my loop isnt working
aa aoo lol
Dan Couper
@DanCouper
May 17 2016 08:40
@ryzokuken failing for me too, in FF and Chrome
Sun
@wisdomdong
May 17 2016 08:40
I'm stuck.My jQuery doesn't run when the page loads.
ruchi125
@ruchi125
May 17 2016 08:40

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

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

var i;

var arr = [ "firstName","lastName","number","likes"];

for(i=0;i<=3;i++)
{
if(firstName == contacts[i].firstName && prop == arr[i])
{
return contacts[i][prop];
}
else

if(firstName !== contacts[i].firstName)
{
return "No such contact";
}
else

if( prop !== arr[i])
{
return "No such property";
}

}

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
looks like the loop isnt working
Dan Couper
@DanCouper
May 17 2016 08:40
@ryzokuken the solution definitely works
Dany Din
@danydin
May 17 2016 08:41
@Athaman ah ok now it makes sense thanks and what exactly /[\W_] means? to remove all sapces and non-alphteics all together?
CamperBot
@camperbot
May 17 2016 08:41
danydin sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
Dany Din
@danydin
May 17 2016 08:42
@ruchi125 no such property should be outside 'if else' do 2 if and then 1 else and at the bottom the 'no such proerpty'
Keone Martin
@Athaman
May 17 2016 08:43
@danydin it's in regular expression format. I'm not the best to explain regexp sorry... https://regex101.com/r/zN0wE9/4 is a website to help check what expressions evaluate to what
ruchi125
@ruchi125
May 17 2016 08:43
@danydin alrite i'll try that
@danydin its still not working
Dany Din
@danydin
May 17 2016 08:44
@ruchi125 show code
ruchi125
@ruchi125
May 17 2016 08:44
the main problem is that the loop is not working

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

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

var i;

var arr = [ "firstName","lastName","number","likes"];

for(i=0;i<=3;i++)
{
console.log(i);

if(firstName == contacts[i].firstName && prop == arr[i])
{
return contacts[i][prop];
}
else

if(firstName !== contacts[i].firstName)
{
return "No such contact";
}
else

if( prop !== arr[i])
{
return "No such property";
}

}

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
here is the code
Dany Din
@danydin
May 17 2016 08:45
why you did i<=3?
ruchi125
@ruchi125
May 17 2016 08:45
the value of i is not increasing and is stuck to 0
cuz i want the loop to run 4 times
since contact is an array of 4 objects
Keone Martin
@Athaman
May 17 2016 08:46
@ruchi125 why not just declare the i in the loop for(var i = 0; i<4; i++)?
ruchi125
@ruchi125
May 17 2016 08:47
i did that too @Athaman but thats not working either
Keone Martin
@Athaman
May 17 2016 08:47
yeah, i'm just asking as a style question
ruchi125
@ruchi125
May 17 2016 08:47
i also tried checking the value of i thru console.log but it shows 0 only.
Keone Martin
@Athaman
May 17 2016 08:48
and you're not going to run a loop if every test sends a return statement
Dany Din
@danydin
May 17 2016 08:48
@ruchi125 just do i < contacts.length;
Dan Couper
@DanCouper
May 17 2016 08:48
@danydin [] is a grouping expression, regex looks for anything in the group.\W is all non-word characters (a-z, A-Z, 0-9). JavaScript Regex counts underscores as word characters, so just doing hello+=- w_orld β.replace(/\W/g, ββ) would return hellow_orld. So the regex /[\W_]/g is saying find any non-word characters or underscores, and .replace is going to replace them
Keone Martin
@Athaman
May 17 2016 08:48
no matter what you put in the first iteration is going to end in return something; and so you'll break out in your first iteration
jessniem
@jessniem
May 17 2016 08:48
Hi, Iβm quite new on javascript. Can anyone tell me how I should write the switch statements? If itβs a letter for example
ruchi125
@ruchi125
May 17 2016 08:49
@ keone oohh rite return statements break out of functions
Dany Din
@danydin
May 17 2016 08:49
@ruchi125 yes thats wat i meant didnt explained it good :x
Keone Martin
@Athaman
May 17 2016 08:49
yeah, it will break out of the function and hence the loop
Dany Din
@danydin
May 17 2016 08:49
@DanCouper ok thanks!!
CamperBot
@camperbot
May 17 2016 08:49
danydin sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
Keone Martin
@Athaman
May 17 2016 08:49
@jessniem i believe the syntax is just case "A":
ruchi125
@ruchi125
May 17 2016 08:49
so what shud i use? it wont let me use document.write
Keone Martin
@Athaman
May 17 2016 08:49
or whichever letter you're looking for
jessniem
@jessniem
May 17 2016 08:50
@Athaman Okay, I guess I have some other problem then
Keone Martin
@Athaman
May 17 2016 08:50
want to send your code here and we can help bug find?
Joel Santos
@St3ps
May 17 2016 08:51
Hey guys is there a reason this line should not work?
$("#cmdFahrenheit").click(weather("imperial")); ruchi125 @ruchi125 May 17 2016 08:51 umm @Athaman then what shud i use, it wont let me use document.write Dany Din @danydin May 17 2016 08:52 @DanCouper really good example thanks very clear and simple [and it's not easy to explain it!] and g means to search global yea CamperBot @camperbot May 17 2016 08:52 danydin sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles: :warning: danydin already gave dancouper points jessniem @jessniem May 17 2016 08:52 @Athaman I found it, I hade to change them all and then it worked, I thought that I could change the first ones and then see that they worked So problem solved, thanks! @Athaman CamperBot @camperbot May 17 2016 08:53 jessniem sends brownie points to @athaman :sparkles: :thumbsup: :sparkles: :cookie: 382 | @athaman |http://www.freecodecamp.com/athaman Keone Martin @Athaman May 17 2016 08:53 @ruchi125 you can use the return statements you just need to fix your if statements so that if they don't match what you're looking for it keeps looping @jessniem glad to hear it :) Joel Santos @St3ps May 17 2016 08:54 To add on my line: That line won't trigger a callback but if i do it like so: $("#cmdFahrenheit").click( function() {
weather("imperial")

});
it will work as intended
ruchi125
@ruchi125
May 17 2016 08:54
@Athaman you think i shud nest the if else?
Joel Santos
@St3ps
May 17 2016 08:54
I just don't understand the diference
Keone Martin
@Athaman
May 17 2016 08:56
@ruchi125 the first level you want to do is check if contacts.firstName === firstName... and have the rest of the for loop nested inside there, that way if the names don't match it just skips over and goes to the next iteration
Dan Couper
@DanCouper
May 17 2016 08:56
@danydin thanks! The \w/\W underscore thing trips people up a bit; itβs historical more than anything - in C, and very many other languages, letters, numbers and underscores are the only allowed characters in variable/identifier names
CamperBot
@camperbot
May 17 2016 08:56
dancouper sends brownie points to @danydin :sparkles: :thumbsup: :sparkles:
ruchi125
@ruchi125
May 17 2016 08:56
ohh alrite got it thanx @Athaman and @danydin :D
CamperBot
@camperbot
May 17 2016 08:56
ruchi125 sends brownie points to @athaman and @danydin :sparkles: :thumbsup: :sparkles:
Keone Martin
@Athaman
May 17 2016 08:57
@ruchi125 also you don't need to make yourself an array with the property names in them. you should just use the prop input value to check
Dany Din
@danydin
May 17 2016 08:57
@ruchi125 :+1:
Gareth Trufitt
@gtrufitt
May 17 2016 08:58
@St3ps \$("#cmdFahrenheit").click(weather("imperial")); will immediately ivoke the weather("imperial") function, as it is a function call, whereas click(function(){..}) is defining a function to be called as a parameter of the click function - you're not executing it immediately but waiting for the event to happen
Dany Din
@danydin
May 17 2016 08:59
@DanCouper kk i see thanks ;)
CamperBot
@camperbot
May 17 2016 08:59
danydin sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:warning: danydin already gave dancouper points
ruchi125
@ruchi125
May 17 2016 08:59
@Athaman but how do i do that? i mean if i write contacts[0].firstname that gives me the property , so can i extract property names from that, ie firstname and lastname etc ?
Dany Din
@danydin
May 17 2016 08:59
anyone knows where i can find-train some easy loop excerises?
ruchi125
@ruchi125
May 17 2016 09:00
@danydin maybe this can help http://www.w3resource.com/
Keone Martin
@Athaman
May 17 2016 09:00
how easy @danydin?
@ruchi125 contacts is already an array... so you can use for(var i = 0; i < contacts.length; i++){}; for your for
then inside that use if(contacts[i].firstName === firstName){}
Dany Din
@danydin
May 17 2016 09:02
@Athaman easy.. like thus here with variation of for switch and so on
ruchi125
@ruchi125
May 17 2016 09:02
@Athaman alrite i'll try that :D thanx again
CamperBot
@camperbot
May 17 2016 09:02
ruchi125 sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
:warning: ruchi125 already gave athaman points
Dany Din
@danydin
May 17 2016 09:02
@ruchi125 thx ]
CamperBot
@camperbot
May 17 2016 09:02
danydin sends brownie points to @ruchi125 :sparkles: :thumbsup: :sparkles:
ruchi125
@ruchi125
May 17 2016 09:02
:D
Dany Din
@danydin
May 17 2016 09:03
Keone Martin
@Athaman
May 17 2016 09:03
not sure about specifically for loops sorry, but there are a few good sites for general algorithms like codewars.com
ruchi125
@ruchi125
May 17 2016 09:03
hahaha thanx :D
Daniel Kelvich
@Daniel-Kelvich
May 17 2016 09:10
whats the difference between "if" and "else if" and "else"?
E Brian Phillips
@bphillips73
May 17 2016 09:10

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

// Only change code below this line
function updateRecords(id, prop, value) {
if (collection[id].tracks[prop].value !== "") {
if (prop !== "tracks") {
collection[id].tracks[prop].value = value;
}
}
if (prop == "tracks") {
if (collection[id].tracks[prop].value !== "") {
collection[id].tracks[prop] = prop.value;
}
}
return collection;
}

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

Keone Martin
@Athaman
May 17 2016 09:11
@Daniel-Kelvich they're used to chain different ifs together.
E Brian Phillips
@bphillips73
May 17 2016 09:12
I did that wrong, but I'm getting "Type error: cannot read property 'artist' of undefined
Keone Martin
@Athaman
May 17 2016 09:12
but only accept the first option that passes a test.
if(5 > 0){
// do some things
}else if (7>0){
// do some other things
}else{
// do another thing
}
in this example @Daniel-Kelvich even though 7 is greater than 0 that section of code won't run because 5>0 will run then will break out of the whole section
if(5 > 0){
//do stuff
}
if(7>0){
//do other stuff
}
in this example both sections of code will run, because 5> 0 will validate and the code will run, then the program will validate 7 > 0 and run that section
else is used like a default, it captures every possibility that you haven't captured using your if statements.
if(number > 10){
//do stuff
}else if(number < 0){
// do other stuff
}else{
// you must have entered a number between 0 and 10 because that is the only way that the program will get to this stage
}
Keone Martin
@Athaman
May 17 2016 09:18
@bphillips73 your logic is a little wonky, that first if statement should be testing whether the value entered is = to "";
E Brian Phillips
@bphillips73
May 17 2016 09:20
i see. yes i feel wonky now :)
Keone Martin
@Athaman
May 17 2016 09:21
give it a rewrite and see how it goes :)
Keone Martin
@Athaman
May 17 2016 09:27
d-cva
@d-cva
May 17 2016 09:28
Got stuck on returning Booolean values.

function isLess(a, b) {
// Fix this code
switch (true){
case (a < b):
break;

default:
break;
}
}

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

what could be done on this code??
Darth Skywalker
May 17 2016 09:30

@d-cva : Try setting answer to boolean value instead of a string.

like

answer = true; // not "true"
//OR

answer = false; // not "false";
Keone Martin
@Athaman
May 17 2016 09:31
@d-cva also using a switch for this example is a lot more complex than necessary
d-cva
@d-cva
May 17 2016 09:32
Wow @adityaparab thanks . Why didn't I thought that :D
CamperBot
@camperbot
May 17 2016 09:32
d-cva sends brownie points to @adityaparab :sparkles: :thumbsup: :sparkles: