These are chat archives for FreeCodeCamp/HelpJavaScript

3rd
Apr 2016
Jesus Arteaga
@HecticHiccups
Apr 03 2016 00:00
What's good
Andrew Vanboxel
@avanbox
Apr 03 2016 00:00
for some reason i cant get the thermometer button on the top of my page to register clicks. Can someone take a look?
i dont have the f/c conversion logic yet just trying to log to conole when the button is clicked
alpox
@alpox
Apr 03 2016 00:01
@HecticHiccups Thats a philosophical question which we don't discuss here i guess :D
Andrew Vanboxel
@avanbox
Apr 03 2016 00:02
lol
alpox
@alpox
Apr 03 2016 00:02
@avanbox I don't see a button there :-/
Andrew Vanboxel
@avanbox
Apr 03 2016 00:02
i assumed it was part of another conversation
the thermometer on the top right corner is a button
alpox
@alpox
Apr 03 2016 00:03
We didn't have a conversation to which that could have fit
Andrew Vanboxel
@avanbox
Apr 03 2016 00:03
it will only show if you accepted location
alpox
@alpox
Apr 03 2016 00:03
There is no thermometer :worried:
Andrew Vanboxel
@avanbox
Apr 03 2016 00:04
are you viewing in this chat window or on codepen?
alpox
@alpox
Apr 03 2016 00:04
Ah now
Somehow it didnt show up before
Andrew Vanboxel
@avanbox
Apr 03 2016 00:04
ahh
alpox
@alpox
Apr 03 2016 00:05
Okay. You set a click handler only on page load, to an element with id FCswitch which doesnt yet exist when this code is run so there was no element on which this handler could have been set
bitgrower
@bitgrower
Apr 03 2016 00:05
@alpox -- wanted to thank someone, and you seemed deserving ... :)
CamperBot
@camperbot
Apr 03 2016 00:05
bitgrower sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:warning: bitgrower already gave alpox points
alpox
@alpox
Apr 03 2016 00:05
@bitgrower Thats grateful :-)
err
bitgrower
@bitgrower
Apr 03 2016 00:06
err ?
alpox
@alpox
Apr 03 2016 00:06
english...
Andrew Vanboxel
@avanbox
Apr 03 2016 00:06
hmm. I tried it outside of the page load loop but same result
alpox
@alpox
Apr 03 2016 00:06
I meant generous xD
not grateful
Moisés Man
@moigithub
Apr 03 2016 00:06
@avanbox for dynamic buttons (added AFTER ur code runs ) u need to use .on("click", ... to install the event handler...
Andrew Vanboxel
@avanbox
Apr 03 2016 00:06
maybe because of the function that inserts the button i geuess
bitgrower
@bitgrower
Apr 03 2016 00:06
probably closely aligned in meaning, enough for it to make sense ... I suspect a spirit of generosity precedes gratitude much of the time ... :)
alpox
@alpox
Apr 03 2016 00:06
@avanbox That would be even worse :-) as @moigithub says, the click event has to be added to the element after it got created.
@avanbox Or the other option is to use event delegation (probably the more elegant solution)
Andrew Vanboxel
@avanbox
Apr 03 2016 00:07
thanks @alpox & @moigithub makes sense
CamperBot
@camperbot
Apr 03 2016 00:07
avanbox sends brownie points to @alpox and @moigithub :sparkles: :thumbsup: :sparkles:
:star: 815 | @moigithub | http://www.freecodecamp.com/moigithub
:star: 468 | @alpox | http://www.freecodecamp.com/alpox
Moisés Man
@moigithub
Apr 03 2016 00:07
if u wanna use .click(... ur button should be present/exist alredy on ur html
Andrew Vanboxel
@avanbox
Apr 03 2016 00:09
yeah ill just have it in html. i was trying to save time but whats you guys or gals said makes sense
alpox
@alpox
Apr 03 2016 00:09
@avanbox let it at the same place and replace it with:
 $("#city_name").on("click", "#FCswitch", function() {
  console.log( "Handler for .click() called." );
});
That should work
This is event delegation. The argument after "click" ("#FCswitch") is a selector for the child element of #city_name.
The event gets set for #city_name which delegates its handler for every #FCswitch child element and tests it for a click
demipixel
@demipixel
Apr 03 2016 00:12
@alpox I need help ;_;
alpox
@alpox
Apr 03 2016 00:12
@demipixel Right at the time i want to lay down my head :D whats up?
demipixel
@demipixel
Apr 03 2016 00:12
var chatText = document.getElementById('chatText');
  var chatTextContainer = document.getElementById('chatTextContainer');

  var height = chatTextContainer.offsetHeight;
  var scrolled = chatTextContainer.scrollTop;
  var totalHeight = chatText.offsetHeight;
  var move = false;
  console.log(scrolled, totalHeight, height, totalHeight - height);
  if (scrolled > totalHeight - height - 15 || totalHeight - height - 15 < 0) {
    move = true;
  }
  chatText.innerHTML += str;
  setTimeout(function() {
    if (move) chatTextContainer.scrollTop = totalHeight;
  }, 0);
I want it to scroll with new text
str contains the text
Justin
@daemedeor
Apr 03 2016 00:12
@alpox if you need sleep i can help
bitgrower
@bitgrower
Apr 03 2016 00:12
@demipixel !!!
demipixel
@demipixel
Apr 03 2016 00:12
HTML heirarchy:
  • chatTextContainer
    • chatText
alpox
@alpox
Apr 03 2016 00:13
@daemedeor I'll do this last one :D
Andrew Vanboxel
@avanbox
Apr 03 2016 00:13
thanks @alpox
CamperBot
@camperbot
Apr 03 2016 00:13
avanbox sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:warning: avanbox already gave alpox points
alpox
@alpox
Apr 03 2016 00:13
@demipixel What do you mean with new text?
demipixel
@demipixel
Apr 03 2016 00:13
It gets put in a function which passes in str
I want chatText.innerHTML += str
But then it needs to auto scroll down the div
So you can see the new text
Justin
@daemedeor
Apr 03 2016 00:13
@demipixel you need to listen for the pageScroll
demipixel
@demipixel
Apr 03 2016 00:14
?
Justin
@daemedeor
Apr 03 2016 00:14
so everytime the page scrolls it calls a method onScroll(),
alpox
@alpox
Apr 03 2016 00:14
@demipixel Hmmh so you need the new height
Justin
@daemedeor
Apr 03 2016 00:14
thats when you do your checks
demipixel
@demipixel
Apr 03 2016 00:14
No
The user isn't scrolling (doesn't matter atm)
Justin
@daemedeor
Apr 03 2016 00:15
oh .
demipixel
@demipixel
Apr 03 2016 00:15
I want it to auto-scroll when new text gets added... .scrollTop doesn't change
And therefore pageScroll wouldn't get called
Moisés Man
@moigithub
Apr 03 2016 00:15
soo.. some functionality like this chat..
last messges pops.. all olders hides
demipixel
@demipixel
Apr 03 2016 00:16
Well
So, yes, like this chat
However if you're scrolled up a bit
It won't do it
alpox
@alpox
Apr 03 2016 00:16
@demipixel cant you just always scroll to the bottom of the element?
demipixel
@demipixel
Apr 03 2016 00:16
(because you're trying to look at something else so it'll continue adding content but it won't autoscroll until you're near the bottom again)
Justin
@daemedeor
Apr 03 2016 00:16
what alpox says
demipixel
@demipixel
Apr 03 2016 00:16
Even if I did it wouldn't work
The point is that if you're scrolled up a bit, it shouldn't auto scroll
Such as in this chat, when you're scrolled up a bit and there's a new message, it won't jump down
alpox
@alpox
Apr 03 2016 00:19
@demipixel chatTextContainer.scrollTop = height; doesnt work?
demipixel
@demipixel
Apr 03 2016 00:19
No, it works
But I think there's an issue with it being added directly after adding new content to the div
alpox
@alpox
Apr 03 2016 00:21
@demipixel What issue?
Is the issue why you put there the timeout?
demipixel
@demipixel
Apr 03 2016 00:21
It won't scroll all the way down, if at all
yeah, I was wondering if adding the text was async or something
alpox
@alpox
Apr 03 2016 00:22
It shouldnt
Do you have a codepen?
demipixel
@demipixel
Apr 03 2016 00:22
No :/
alpox
@alpox
Apr 03 2016 00:23
I don't exactly know what works and what not now :D
And without the possibility to test its always quite hard since there may be CSS issues too
@demipixel But you may try this:
var chatText = document.getElementById('chatText');
  var chatTextContainer = document.getElementById('chatTextContainer');
  var height = chatTextContainer.offsetHeight;
  var scrolled = chatTextContainer.scrollTop;
  var totalHeight = chatText.offsetHeight;
  var move = false;

  if (scrolled > totalHeight - height - 15 || totalHeight - height - 15 < 0) {
    move = true;
  }
  chatText.innerHTML += str;
  if (move) chatTextContainer.scrollTop = chatTextContainer.offsetHeight;
Andrew Vanboxel
@avanbox
Apr 03 2016 00:26
@alpox can I pm you when your not busy? I still cant get it working.......
alpox
@alpox
Apr 03 2016 00:26
@demipixel Without any guaranty :D
@avanbox yup
demipixel
@demipixel
Apr 03 2016 00:26
That's what I had before lol
demipixel
@demipixel
Apr 03 2016 00:28
No
Setting the scrollHeight from the dev console works fine
alpox
@alpox
Apr 03 2016 00:28
@demipixel Then use this:
if (move) chatTextContainer.scrollTop = chatTextContainer.clientHeight;
Just to try
Moisés Man
@moigithub
Apr 03 2016 00:31
i think clientHeight only contains the "visible" part
demipixel
@demipixel
Apr 03 2016 00:33
I'll see what I can do
alpox
@alpox
Apr 03 2016 00:35
@demipixel hmm no wait chatTextContainer.scrollTop = chatText.offsetHeight; does it in my example
@demipixel But maybe you should calculate your stuff after you added the text
demipixel
@demipixel
Apr 03 2016 00:37
Well
The problem with that
Is that I'm trying to test how much they've scrolled
If they're not near the bottom, I don't want to scroll
Well, they'll be less near the bottom once I've added text :P
Brandon Lee
@brandonlee781
Apr 03 2016 00:38
@alpox After a short Netflix break and staring very hard at my computer I finally figured out closures. Thank you very much. I completed the challenge, but I'm wondering if there's a better way to check if an argument is an integer besides Number.isInteger() because arrays of integers pass true when put in that .
CamperBot
@camperbot
Apr 03 2016 00:38
brandonlee781 sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star: 469 | @alpox | http://www.freecodecamp.com/alpox
alpox
@alpox
Apr 03 2016 00:38
@demipixel True, true :D
Moisés Man
@moigithub
Apr 03 2016 00:38
@brandonlee781 typeof probably ?
Brandon Lee
@brandonlee781
Apr 03 2016 00:39
@moigithub You're probably right, thanks!
CamperBot
@camperbot
Apr 03 2016 00:39
brandonlee781 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 816 | @moigithub | http://www.freecodecamp.com/moigithub
cyounger88
@cyounger88
Apr 03 2016 00:39

I need help. function queue(arr, item) {
// Your code here
arr.push(item);
var removed = 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(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

what am i doing wrong?
alpox
@alpox
Apr 03 2016 00:40
@brandonlee781 As @moigithub suggests, typeof is one solution or you can use !isNaN(nr)
Moisés Man
@moigithub
Apr 03 2016 00:40
@cyounger88 shift is a method... so u need () parenthesis at the end
var removed = arr.shift();
and u need to return the "removed" element..so
return item; <-- need to fix that line
demipixel
@demipixel
Apr 03 2016 00:40
@alpox Look at this for one second and tell me I'm not crazy
console.log(scrolled, totalHeight, height, totalHeight - height, move);
chatText.innerHTML += str;
if (move) chatTextContainer.scrollTop = totalHeight;
alpox
@alpox
Apr 03 2016 00:41
@demipixel Because of what? :-)
demipixel
@demipixel
Apr 03 2016 00:41
0 0 400 -400 true
0 25 400 -375 true
0 46 400 -354 true
0 46 400 -354 true
0 67 400 -333 true
0 67 400 -333 true
0 88 400 -312 true
0 88 400 -312 true
??????
alpox
@alpox
Apr 03 2016 00:41
@demipixel Well you are hopefully aware that totalHeight is not the real height anymore after you added str
demipixel
@demipixel
Apr 03 2016 00:41
scrolled == chatTextContainer.scrollTop
So I keep setting "scrolled" each time but it stays at 0?
cyounger88
@cyounger88
Apr 03 2016 00:42
thanks @moigithub
CamperBot
@camperbot
Apr 03 2016 00:42
cyounger88 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
demipixel
@demipixel
Apr 03 2016 00:42
totalHeight is way more than I need to scroll, which is fine
CamperBot
@camperbot
Apr 03 2016 00:42
:star: 817 | @moigithub | http://www.freecodecamp.com/moigithub
Moisés Man
@moigithub
Apr 03 2016 00:43
before = scrollHeight;
chatText.innerHTML += str;
after = scrollHeight;
howMuchScrolled = after-before;
??
if howMuchScrolled > XX (move ?? )
    scrollTop = scrollHeight
demipixel
@demipixel
Apr 03 2016 00:46
console.log(scrolled, totalHeight, height, totalHeight - height, move);
  chatText.innerHTML += str;
  if (move) chatTextContainer.scrollTop = totalHeight;
  if (move) console.log('moved '+chatTextContainer.scrollTop,'suppose to move',totalHeight)
0 0 400 -400 true
moved 0 suppose to move 0
0 25 400 -375 true
moved 0 suppose to move 25
0 46 400 -354 true
moved 0 suppose to move 46
0 46 400 -354 true
moved 0 suppose to move 46
0 67 400 -333 true
moved 0 suppose to move 67
0 67 400 -333 true
moved 0 suppose to move 67
0 88 400 -312 true
moved 0 suppose to move 88
0 88 400 -312 true
moved 0 suppose to move 88
alpox
@alpox
Apr 03 2016 00:46
@demipixel can your content scroll? :-) overflow: auto
demipixel
@demipixel
Apr 03 2016 00:46
yes
I literally do a=b and then log a and b
and a ≠ b
i think im crazy
"If set to a value greater than the maximum that the content can be scrolled, scrollTop is set to the maximum."
alpox
@alpox
Apr 03 2016 00:47
@demipixel Can you provide a bigger picture of where the code is? Like in which function the code is and a little excerpt of the html
demipixel
@demipixel
Apr 03 2016 00:48
Basically, how long do I have to wait for .scrollTop to allow me to scroll further
Muhammad Osman A.J.
@moajday
Apr 03 2016 00:48
This message was deleted
alpox
@alpox
Apr 03 2016 00:51
@demipixel I don't think you have to wait. I think you have something else what messes it up
alpox
@alpox
Apr 03 2016 00:57
@demipixel Ehh i see why the log behaves like that
Silly me thought too far
demipixel
@demipixel
Apr 03 2016 00:57
:/
alpox
@alpox
Apr 03 2016 00:57
It seems that there is a the container which has a height of 400 and text which was from 0-88
so the text was never big enough to overcome the 400
means, there exists no scrollbar and no scrolltop can be set
demipixel
@demipixel
Apr 03 2016 00:58
It scrolls sometimes
alpox
@alpox
Apr 03 2016 00:58
Sometimes doesn't sound very constant :D
But from what i see in these numbers there can be no scroll
demipixel
@demipixel
Apr 03 2016 00:58
*consistent
But there is sometimes, so clearly it isn't "no scroll"
alpox
@alpox
Apr 03 2016 00:59
Does there appear a scrollbar?
And how can it scroll when the content is smaller than the container?
demipixel
@demipixel
Apr 03 2016 01:00
You know what
I bet I know what the issue was
It contained images. If they're not loaded yet, the height won't be correct immediately
alpox
@alpox
Apr 03 2016 01:00
Thats possible
demipixel
@demipixel
Apr 03 2016 01:00
One question
alpox
@alpox
Apr 03 2016 01:00
You don't use jquery?
demipixel
@demipixel
Apr 03 2016 01:01
I do
Not in this case though
Because stuff was getting messed up
Quick question:
If an image is cached (been loaded on the page before), will it automatically be loaded?
*synchronously?
Or will it be async every time?
Hmmm
Maybe if I set the height, it won't need to wait to load because it'll already know it
Hey I think that worked
alpox
@alpox
Apr 03 2016 01:08
@demipixel Okay here is what you can do:
chatText.innerHTML += str;
$("#chatText > img").load(function() {
 // picture loaded
});
demipixel
@demipixel
Apr 03 2016 01:09
But it worked
alpox
@alpox
Apr 03 2016 01:09
Ah yeah setting the height surely works
demipixel
@demipixel
Apr 03 2016 01:09
sooo
alpox
@alpox
Apr 03 2016 01:09
If you can know the height
demipixel
@demipixel
Apr 03 2016 01:09
But
Glad I figured it out
I've been spending so much time on this...
alpox
@alpox
Apr 03 2016 01:09
:thumbsup:
And i really have to go to bed now :D
Heheh yeah noone could know that you have pictures ther :D
demipixel
@demipixel
Apr 03 2016 01:11
sry
top secret project ;D
alpox
@alpox
Apr 03 2016 01:11
:P i see
Well cannot be thaat secret, we already know that its a chat :P
But what chat....
So i'm off, cya ^^
demipixel
@demipixel
Apr 03 2016 01:12
It's not a chat lol
That's one part of it
alpox
@alpox
Apr 03 2016 01:12
Okay ^^
I'm going to do a bigger project for my own too
soon..
When i learned myself some Elixir ^^
demipixel
@demipixel
Apr 03 2016 01:17
gl
alpox
@alpox
Apr 03 2016 01:17
Thanks ^^
Elbert Cortez
@trip16661
Apr 03 2016 01:18
can anyone help me why im not getting the json from the api ?
alpox
@alpox
Apr 03 2016 01:25
@trip16661 Add jQuery to your page in the settings
@trip16661 And your API doesn't support jsonp requests so you have to add:
https://crossorigin.me/ in front of your url:
$(document).ready(function() {
  $("#submit").on("click", function() {
    $.getJSON('https://crossorigin.me/http://api.forismatic.com/api/1.0/?method=getQuote&key=457653&format=json&lang=en', function(quoteData) {
      $("#wiseWords").html(JSON.stringify(quoteData));
    });
  });
});
Kevin Mulligan
@kmulligan
Apr 03 2016 01:27
@alpox how did you know it didn't support jsonp requests? Learning here..
Andrew Charlebois
@andrewchar
Apr 03 2016 01:28
having some problems with this code. its counting down correctly but it skips when it gets to anything with 2 zeros. "1:00" it counts 1:01 to 0:59. ive tried a couple different ways to fix like if i set the if statement to seconds > (-1) it doesnt skip the zero but then the clock will stop at 0:0-1 instead of the correct 0:00, im at a loss with it :(
function startSession(minutes) {
    var seconds = 60;
    var mins = minutes;
    function tick() {
        var counter = document.getElementById("session-time-on-clock");
        var current_minutes = mins-1
        seconds--;
        console.log(seconds);
        counter.innerHTML = current_minutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds);
        if( seconds > 0 ) {
            mInterv = setTimeout(tick, 250);
        } else {
            if(mins > 1){
                startSession(mins-1);           
            } 
        }
    }
    tick();
}
alpox
@alpox
Apr 03 2016 01:29

@kmulligan testing it... I added a callback=? to the url and got

SyntaxError: Unexpected token ':'. Parse error.

Kevin Mulligan
@kmulligan
Apr 03 2016 01:29
@alpox ah, ok, thanks
CamperBot
@camperbot
Apr 03 2016 01:29
kmulligan sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star: 470 | @alpox | http://www.freecodecamp.com/alpox
alpox
@alpox
Apr 03 2016 01:30
What usually happens when the API doesnt support jsonp, since the response from the server to the jsonp request was not in json format
In this case you have to request the service through a proxy server (like crossorigin.me)
Elbert Cortez
@trip16661
Apr 03 2016 01:34
@alpox one question, now it works but it doesn't change the value
every time i hit the submit button
it always send the same quote
PHPman
@dmitrikonnikov
Apr 03 2016 01:44
i am working on the word blanks js can someone help me?
James Bond
@Dman89
Apr 03 2016 01:46
http://codepen.io/livinglegendparagon/pen/wGrYzo?editors=0010
can you tell me why my temp number wont appear?
genn
@gennkill
Apr 03 2016 02:23
hello is a+=1; and a++; pretty much the same thing?
James Bond
@Dman89
Apr 03 2016 02:23
@gennkill yes
@gennkill umm wait
Chuck Adams
@chuckadams
Apr 03 2016 02:24
they have the same effect
James Bond
@Dman89
Apr 03 2016 02:24
^
Chuck Adams
@chuckadams
Apr 03 2016 02:25
different as expressions, the first is hardly ever used that way tho
Paul Borawski
@iAmNawa
Apr 03 2016 02:31
@gennkill a++ means increment a+=1 means a = a+1
genn
@gennkill
Apr 03 2016 02:32
alright
John Pyles
@japyles
Apr 03 2016 02:36
@AndyRoush Each individual array in myArray can be subsetted with a number starting at 0
so … myArray[0] will equal [1,2,3]
Andy Roush
@AndyRoush
Apr 03 2016 02:37
That makes sense... but how is arr[1][2] equal to 6?
John Pyles
@japyles
Apr 03 2016 02:37
@AndyRoush So if you want to get the ‘1’ from the zeroth array you would subset again. So, myArray[0][0] will give you the ‘1'
@AndyRoush The 6 is in the 2nd array and in the 3rd position. Remember it’s zero-based
Andy Roush
@AndyRoush
Apr 03 2016 02:39
oooohhhh
ok I think I get it now!!
let me try
AudioGen
@AudioGen
Apr 03 2016 02:39
speaking of multi dimensional arrays , What do I need to do here
Andy Roush
@AndyRoush
Apr 03 2016 02:39
holy crap @japyles I got it... thank you very much for your help!
CamperBot
@camperbot
Apr 03 2016 02:39
andyroush sends brownie points to @japyles :sparkles: :thumbsup: :sparkles:
:star: 273 | @japyles | http://www.freecodecamp.com/japyles
John Pyles
@japyles
Apr 03 2016 02:39
@AndyRoush Glad I could help :)
@AudioGen I do not see what you are trying to do
AudioGen
@AudioGen
Apr 03 2016 02:42

function largestOfFour(arr){



var largeNum = [];
  for(var i = 0; i < arr.length; i++){
  //get the one value from the nested array
   largeNum = largeNum + arr[i].sort();
   }
   return largeNum;
}


document.getElementById("fun").innerHTML = largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
return the largest number in each sub-array
lol the DOM stuff was from me trying to work it out on another program
John Pyles
@japyles
Apr 03 2016 02:44
@AudioGen what are the instructions?
AudioGen
@AudioGen
Apr 03 2016 02:45
to return a new array with the largest Number of each sub-array
so an array with [5, 27, 39, 1001]
John Pyles
@japyles
Apr 03 2016 02:47
@AudioGen So, you need to find a way to extract the highest number from each sub array and push it to a new array. The new array will have all of the largest numbers of the sub array. You need to use loops and comparisons
Dylan
@dhcodes
Apr 03 2016 02:47
@AudioGen I think you need to push it to the array instead of =
Nathanael Milien
@naelmilien
Apr 03 2016 02:50
Hi everyone, I'm having trouble with the first JSON exercise. The instructions are to add a new to the myMusic JSON object. Here's what it looks like :
var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
// Add record here
];
I assume that the push method won't work here
John Pyles
@japyles
Apr 03 2016 02:53
@naelmilien You should be able to use push
AudioGen
@AudioGen
Apr 03 2016 02:55
uggh
so close
not working
John Pyles
@japyles
Apr 03 2016 02:56
@AudioGen What do you have so far?
Nathanael Milien
@naelmilien
Apr 03 2016 02:58
hi @japyles to do that i'd need to declare a new variable and then put all the properties and values inside, right? suppose i call the new variable newAlbum. I need to myMusic.push(newAlbum); right?
AudioGen
@AudioGen
Apr 03 2016 02:58
I posted it above
updated
Kent
@kenthub
Apr 03 2016 03:00
Working on Bonfire Title Case a Sentence and i'm stuck here
function titleCase(str) {
  str.toLowerCase();
  str.split(' ');

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

    // If the string at index[0]
    // Convert that to UpperCase
    if (str[i][0]){
      str[i][0].toUpperCase();

    }

  }

  return str;
}

titleCase("I'm a little tea pot");
any pointers?
AudioGen
@AudioGen
Apr 03 2016 03:00

function largestOfFour(arr){



var largeNum = [];

  for(var i = 0; i < arr.length; i++){
  //get the one value from the nested array
  largeNum.push(arr[i].sort(arr[i]));

   }
   return largeNum;
}


document.getElementById("fun").innerHTML = largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Mark Gillespie
@markblack1831
Apr 03 2016 03:03
I’m trying to create an algorithm to convert celsius to fahrenheit. Can anyone take a look at my code to see what I’m doing wrong?
AudioGen
@AudioGen
Apr 03 2016 03:03
@kenthub Is Bonfire titlecase where every first letter of a word is capitalized?
Mark Gillespie
@markblack1831
Apr 03 2016 03:03

‘code’function convert(celsius) {
// Only change code below this line

var fahrenheit = 9/5+32;
// Only change code above this line
if ( typeof fahrenheit !== 'undefined' ) {
return fahrenheit;
} else {
return 'fahrenheit not defined';
}
}

// Change the inputs below to test your code
convert(20);

Kent
@kenthub
Apr 03 2016 03:03
@audio yes
@AudioGen yes
David Weedmark
@DavidWeedmark
Apr 03 2016 03:05
@markblack1831 your fahrenheit needs to convert the celsius. you've got the numbers but not the celsius part in your third line i.e. var fahrenheit = celsius * 9 .... etc
Mark Gillespie
@markblack1831
Apr 03 2016 03:06
@DavidWeedmark Thank you so much!
CamperBot
@camperbot
Apr 03 2016 03:06
markblack1831 sends brownie points to @davidweedmark :sparkles: :thumbsup: :sparkles:
:star: 447 | @davidweedmark | http://www.freecodecamp.com/davidweedmark
John Pyles
@japyles
Apr 03 2016 03:06
@naelmilien What is the name of the challenge?
David Weedmark
@DavidWeedmark
Apr 03 2016 03:07
@markblack1831 no prob
John Pyles
@japyles
Apr 03 2016 03:07
@naelmilien Sorry for the delay. I got pulled away
AudioGen
@AudioGen
Apr 03 2016 03:07
@kenthub you got to get charAT initial position to capital and the rest of the substring has to be lowercase
Kent
@kenthub
Apr 03 2016 03:09
i'll look at charAt on MDN then. Haven't played with it much
@AudioGen thanks
CamperBot
@camperbot
Apr 03 2016 03:09
kenthub sends brownie points to @audiogen :sparkles: :thumbsup: :sparkles:
:star: 333 | @audiogen | http://www.freecodecamp.com/audiogen
John Pyles
@japyles
Apr 03 2016 03:14
@naelmilien You can certainly use push. You just set it up like the example. you do not have to set up a new id
@naelmilien Does that make sense?
@naelmilien you are just pushing to myMusic
Nathanael Milien
@naelmilien
Apr 03 2016 03:16
@japyles like this myMusic.push(); ?
without putting anything inside?
John Pyles
@japyles
Apr 03 2016 03:17
@naelmilien Absolutely! That will do it
@naelmilien no
@naelmilien you have to put inside what you want pushed to myMusic
@naelmilien Don’t forget to use {} around the whole thing you want to push inside the brackets
Nathanael Milien
@naelmilien
Apr 03 2016 03:18
@japyles let me try
John Pyles
@japyles
Apr 03 2016 03:24
@AudioGen You have to do a nested for loop to access the numbers inside the sub arrays
Nathanael Milien
@naelmilien
Apr 03 2016 03:24
@japyles Thanks, for your help. It worked. you were of great help
CamperBot
@camperbot
Apr 03 2016 03:24
naelmilien sends brownie points to @japyles :sparkles: :thumbsup: :sparkles:
:star: 274 | @japyles | http://www.freecodecamp.com/japyles
John Pyles
@japyles
Apr 03 2016 03:25
@naelmilien Glad I could be of assitance :)
Nathanael Milien
@naelmilien
Apr 03 2016 03:25
@japyles i looked everywhere online and they were trying to make me use loops and i'm not even there yet with freecodecamp lol
John Pyles
@japyles
Apr 03 2016 03:26
@naelmilien What are they trying to get you to use loops on?
Nathanael Milien
@naelmilien
Apr 03 2016 03:28
on that same problem i asked about...maybe i wasn't searching the right way
John Pyles
@japyles
Apr 03 2016 03:29
@naelmilien Oh yes. They were trying to do something else. The course has not yet taken you to that point :)
Nathanael Milien
@naelmilien
Apr 03 2016 03:30
lol, i figured...thanks again @japyles ....since my brain is hurting right now, i'm going to rest it for a bit...have a great weekend :)
CamperBot
@camperbot
Apr 03 2016 03:30
naelmilien sends brownie points to @japyles :sparkles: :thumbsup: :sparkles:
:warning: naelmilien already gave japyles points
John Pyles
@japyles
Apr 03 2016 03:30
@naelmilien You as well. I know how you feel :0
:)
Taur'e Anthony
@k0decraft
Apr 03 2016 03:39

Hi guys, I'm not following switch statements well. I'm on the "Selecting from many options with Switch Statements" section. I understand their like if statements, and I have Googled around but no resource is helping me comprehend it.

I have this code setup....in the console output it returns the string alpha, that's what I need, but the set-up here looks wrong....guys?

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

  switch (val) {

    case val:
      answer = 'alpha';
      break;



  }

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

// Change this value to test
myTest(1);
//myTest(2);
Paul Borawski
@iAmNawa
Apr 03 2016 03:43
anyone know how to make an item rotate with jQuery while the use scrolls down
?
user**
John Pyles
@japyles
Apr 03 2016 03:45
@k0decraft It looks like you need to replace val after ‘case’ with ‘answer’ and then set that to equal ‘alpha'
@k0decraft or better yet, : alpha, not = alpha
AudioGen
@AudioGen
Apr 03 2016 03:47
bloop
anyone know how to remove/disable the green popup notifications?
John Pyles
@japyles
Apr 03 2016 03:48
@AudioGen It’s in the upper right corner with the levels looking icon
AudioGen
@AudioGen
Apr 03 2016 03:48
change it to mute?
John Pyles
@japyles
Apr 03 2016 03:49
@AudioGen Yes, that should do
AudioGen
@AudioGen
Apr 03 2016 03:49
@japyles Ok Thanks
CamperBot
@camperbot
Apr 03 2016 03:49
audiogen sends brownie points to @japyles :sparkles: :thumbsup: :sparkles:
:star: 275 | @japyles | http://www.freecodecamp.com/japyles
Taur'e Anthony
@k0decraft
Apr 03 2016 03:49
@japyles
Is this what you mean?...
switch (val) {

    case 'answer':
      answer = 'alpha';
      break;



  }
AudioGen
@AudioGen
Apr 03 2016 03:55
@k0decraft The argument you are passing into the function is what you want to test the case by
John Pyles
@japyles
Apr 03 2016 03:55
@k0decraft I must apologize. I think I led you slightly astray. Not purposely. I was not quite clear at first what you were doing. Which challenge is this? Let me look at the directions completely
Taur'e Anthony
@k0decraft
Apr 03 2016 03:55
@japyles No worries, it's the "Selecting from many options with Switch Statements" challenge.
@AudioGen Thanks, I think I follow switch statements that far, but I feel there's still something about it I'm not grasping.
CamperBot
@camperbot
Apr 03 2016 03:56
k0decraft sends brownie points to @audiogen :sparkles: :thumbsup: :sparkles:
:star: 335 | @audiogen | http://www.freecodecamp.com/audiogen
AudioGen
@AudioGen
Apr 03 2016 03:58
@k0decraft the argument you are passing into the function you have there is not a 'string'
Benjamin Gonzalez
@xasuma
Apr 03 2016 03:58
Can someone please help me with "Where do I belong" algorithm.
The only thing I am missing is getIndexToIns([5, 3, 20, 3], 5) should return 2. and I can't figure out why.
function getIndexToIns(arr, num) {

  arr.sort(function(a,b){ //this function will sort the arr in ascending order.
    return a - b;
  });

  var index;
  var i = 0;

  if(num > arr[i]){   
    while(num >arr[i]){
      index = arr.indexOf(arr[i]) + 1;
      i++;
    }
  }else{
    index = 0;
  }
  return index;
}

getIndexToIns([5, 3, 20, 3], 5);
it is returning 1 instead of 2.
Elbert Cortez
@trip16661
Apr 03 2016 04:03
@xasuma mine is a 5 lines answer
dunno why you made it that complicated
John Pyles
@japyles
Apr 03 2016 04:04
@xasuma Yes indeed. No while loop needed
Taur'e Anthony
@k0decraft
Apr 03 2016 04:04

@AudioGen Ok, this is what I originally had...

switch (val) {

    case val:
      answer = 'alpha';
      break;



  }

This returned the string alpha which is what I want, is this on the correct path? If so, how do I include the second statement?

Elbert Cortez
@trip16661
Apr 03 2016 04:06
you only need indexOf to loop through
AudioGen
@AudioGen
Apr 03 2016 04:07
@k0decraft give me a moment, I'm going to test that out, I don't see how that worked but that's not what you want for multiple cases
Taur'e Anthony
@k0decraft
Apr 03 2016 04:08
@AudioGen Ha, yea the console output returned the string.
John Pyles
@japyles
Apr 03 2016 04:09
@k0decraft If you look at the instructions at the side it tells you what to put after case. Such as, 1, 2, etc. You then need to test if val equals one of those and if so what to return in the function
AudioGen
@AudioGen
Apr 03 2016 04:09
@k0decraft I think it's just treating it as an object
Benjamin Gonzalez
@xasuma
Apr 03 2016 04:10
@trip16661 I can't understand your code. The way I did it makes sense to me but I cannot make sense why it isn't working for that particular case.
AudioGen
@AudioGen
Apr 03 2016 04:10
I tried another case with that setup and it still returns "alpha"
John Pyles
@japyles
Apr 03 2016 04:11
@AudioGen It should only return ‘alpha’ if val = 1
Taur'e Anthony
@k0decraft
Apr 03 2016 04:11
@japyles I'm looking at the instructions, I just don't follow, it's why I'm asking.
AudioGen
@AudioGen
Apr 03 2016 04:11
@k0decraft Do you think me writing out a mock switch statement might help?
Taur'e Anthony
@k0decraft
Apr 03 2016 04:12
@AudioGen Anything would help me follow what I'm missing at this point, shoot dude.
Benjamin Gonzalez
@xasuma
Apr 03 2016 04:13
@trip16661 Ah after staring at your code this whole time I finally get it. lol Thanks!
CamperBot
@camperbot
Apr 03 2016 04:13
xasuma sends brownie points to @trip16661 :sparkles: :thumbsup: :sparkles:
:star: 276 | @trip16661 | http://www.freecodecamp.com/trip16661
John Pyles
@japyles
Apr 03 2016 04:13
@k0decraft You should set up the switch statement as case 1: <line break> return ‘alpha’; . Then set the rest up the same way. Does that make sense?
Andrew Charlebois
@andrewchar
Apr 03 2016 04:13
is there a way that i can hook up some javascript to a button so that when i click a button, it will do w.e the button does, and then have it hide itself, like adding class of display:none to it to have another button show up?
i want to have a start/stop button instead of having two buttons
Elbert Cortez
@trip16661
Apr 03 2016 04:14
@xasuma what code ?xDD
not sure i know what you talking about
Paul Borawski
@iAmNawa
Apr 03 2016 04:14
@andrewchar yes
Benjamin Gonzalez
@xasuma
Apr 03 2016 04:14
@trip16661 your solution, I was looking at it this whole time to make sense of it.
Elbert Cortez
@trip16661
Apr 03 2016 04:15
where do you see it? xDD
you can see my solution from previous challenges?
Benjamin Gonzalez
@xasuma
Apr 03 2016 04:15
@trip16661 in your profile, you can see people's answers as long as they have it set to public.
Elbert Cortez
@trip16661
Apr 03 2016 04:15
ahhh
@xasuma i didn't even know xD
Benjamin Gonzalez
@xasuma
Apr 03 2016 04:15
you learn something new everyday :D
Andrew Charlebois
@andrewchar
Apr 03 2016 04:15
i know how to do this for something like.. media queries but im not sure how to hook it up with a button. or hooking a button up to some jquery/js to have it add class of display:none to itself and add class of display: inline or something to another button to take its place
Elbert Cortez
@trip16661
Apr 03 2016 04:16
i thought you was talking about the code i sent before and i was "it don't have anything to do with that"
Andrew Charlebois
@andrewchar
Apr 03 2016 04:16
or is there a more simple way of doing this?
Benjamin Gonzalez
@xasuma
Apr 03 2016 04:16
lol!
Sudeep Narkar
@sudeepnarkar
Apr 03 2016 04:16
Anyone doing basic javascript here?
Benjamin Gonzalez
@xasuma
Apr 03 2016 04:16
I am
well no actually im not, nvm
Sudeep Narkar
@sudeepnarkar
Apr 03 2016 04:17
Lol
Taur'e Anthony
@k0decraft
Apr 03 2016 04:17
@japyles Thanks for your input man, but I'm just staring at the code. It's not clicking yet. As easy as it may be for ya'll lol.
CamperBot
@camperbot
Apr 03 2016 04:17
k0decraft sends brownie points to @japyles :sparkles: :thumbsup: :sparkles:
:star: 276 | @japyles | http://www.freecodecamp.com/japyles
Benjamin Gonzalez
@xasuma
Apr 03 2016 04:17
got confused with algorithms. my bad
Sudeep Narkar
@sudeepnarkar
Apr 03 2016 04:17
Hmm
Benjamin Gonzalez
@xasuma
Apr 03 2016 04:17
But I did them, so maybe I can help .
Sudeep Narkar
@sudeepnarkar
Apr 03 2016 04:17
How are you liking the course?
Elbert Cortez
@trip16661
Apr 03 2016 04:18
how much you are hating it :P
Benjamin Gonzalez
@xasuma
Apr 03 2016 04:18
I think it's great, I have learned a lot!
Rex Smith Jr.
@rsmith731
Apr 03 2016 04:18
can someone help with me with the Gold Code exercise?
Paul Borawski
@iAmNawa
Apr 03 2016 04:18
@andrewchar make the onlick call a function that finishes it’s task and then deletes itself
AudioGen
@AudioGen
Apr 03 2016 04:18
function myTest(val){
 var answer = " ";
switch(val){
case 1: console.log("alpha");
break;
case 2: console.log("cheese");
break;
case 3: console.log("moon");
break;
default: console.log("Spaghettios");
}
return answer;
}
myTest(3);
Paul Borawski
@iAmNawa
Apr 03 2016 04:19
@andrewchar it’s asynchronous so it should be able to do something and then hide itself
AudioGen
@AudioGen
Apr 03 2016 04:19
So the argument 3 passed to myTest Should match the case 3 which should console.log "moon"
Andrew Charlebois
@andrewchar
Apr 03 2016 04:20
@iAmNawa just a button to start a timer and hide itself so a button then shows up for stop timer
Taur'e Anthony
@k0decraft
Apr 03 2016 04:20
@AudioGen Thanks man, but now I was playing with the code with @japyles input and now I can follow it. Thanks to both you guys!
CamperBot
@camperbot
Apr 03 2016 04:20
k0decraft sends brownie points to @audiogen and @japyles :sparkles: :thumbsup: :sparkles:
:warning: k0decraft already gave japyles points
Riful
@timburrows
Apr 03 2016 04:20
Could someone help me with the Javascript exercise called Accessing Nested Arrays in Json?
CamperBot
@camperbot
Apr 03 2016 04:20
:warning: k0decraft already gave audiogen points
Sudeep Narkar
@sudeepnarkar
Apr 03 2016 04:20
answer=console.log("moon");
It should be I guess
Riful
@timburrows
Apr 03 2016 04:20
It seems to introduce a new concept that hasn't been explained
Sudeep Narkar
@sudeepnarkar
Apr 03 2016 04:21
@AudioGen @sudeepnarkar
answer=console.log("moon");
It should be I guess
AudioGen
@AudioGen
Apr 03 2016 04:21
Yep
Chase
@Belax8
Apr 03 2016 04:21
'''
CamperBot
@camperbot
Apr 03 2016 04:21
:bulb: to format code use backticks! ``` more info
Paul Borawski
@iAmNawa
Apr 03 2016 04:21
why don’t you use the same button to start the timer and change the button to say stop @andrewchar
@camperbot hey man what’s up
Elbert Cortez
@trip16661
Apr 03 2016 04:22
@AudioGen what challenge is that?
Paul Borawski
@iAmNawa
Apr 03 2016 04:22
camperbot help
AudioGen
@AudioGen
Apr 03 2016 04:22
@trip16661 I made that up off the cuff, to attempt to k0decraft
Paul Borawski
@iAmNawa
Apr 03 2016 04:22
@Belax8 type three backticks and press enter
AudioGen
@AudioGen
Apr 03 2016 04:22
to help*
Andrew Charlebois
@andrewchar
Apr 03 2016 04:23
@iAmNawa ionno, just looking for the best way
Riful
@timburrows
Apr 03 2016 04:23
Anyone willing to help?
Paul Borawski
@iAmNawa
Apr 03 2016 04:23
@RifuI yes
Taur'e Anthony
@k0decraft
Apr 03 2016 04:23
@AudioGen It is definitely helpful
Riful
@timburrows
Apr 03 2016 04:23
I'd just like to know what this new syntax is
Chase
@Belax8
Apr 03 2016 04:23
// 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 update(id, prop, value) {
  if(id[value] !== "" && id[prop] !== "tracks") {
    id[prop] = value;
  }
  else if(id[prop] === "tracks" && id[value] !== "") {
    id.tracks.push(value);
  }
  else if(id[value] === "") {
    id[prop].shift();
  }

  return collection;
}

// Alter values below to test your code
update(5439, "artist", "ABBA");
Paul Borawski
@iAmNawa
Apr 03 2016 04:23
I made a music player a while back @andrewchar that changed the play button to a pause button, let me find the code real quick
Chase
@Belax8
Apr 03 2016 04:24
It keeps saying TypeError: Cannot create property 'artist' on number '5439' What am I doing wrong?
Riful
@timburrows
Apr 03 2016 04:24
Looks like this:
type: "flowers",
list: [
"rose",
"tulip",
"dandelion"
]
Paul Borawski
@iAmNawa
Apr 03 2016 04:25
Elbert Cortez
@trip16661
Apr 03 2016 04:25
I'm so stuck trying to get a random json fom an api
i just get the same vale and doesn't change ever D:
AudioGen
@AudioGen
Apr 03 2016 04:25
@RifuI If it's a nested array that is definitely not all the code :)
Elbert Cortez
@trip16661
Apr 03 2016 04:25
can somebody help me out?
Riful
@timburrows
Apr 03 2016 04:26
// Setup
var myPlants = [
  { 
    type: "flowers",
    list: [
      "rose",
      "tulip",
      "dandelion"
    ]
  },
  {
    type: "trees",
    list: [
      "fir",
      "pine",
      "birch"
    ]
  }  
];

// Only change code below this line

var secondTree = ""; // access the nested array here.
Chase
@Belax8
Apr 03 2016 04:26
Any help? Why is is returning TypeError: Cannot create property 'artist' on number '5439'?
John Pyles
@japyles
Apr 03 2016 04:26
@k0decraft Oh yes, don’t forget the breaks :). You are doing well
Sudeep Narkar
@sudeepnarkar
Apr 03 2016 04:27
@Belax8 Hi. Shoudnt it be collection[id].
AudioGen
@AudioGen
Apr 03 2016 04:28
@RifuI so you access an array with an index which is a value stored by the position in the array. array indexes start at 0, so you got to count from 0
Riful
@timburrows
Apr 03 2016 04:28
I understand arrays
but what is trees and list?
are these keywords?
and then in the example it provides, these are substituted with animalType and names?
AudioGen
@AudioGen
Apr 03 2016 04:29
@AudioGen you have an array inside another array now, so you need a pair of indexes to grab the value you want
Riful
@timburrows
Apr 03 2016 04:30
Yes but what is the array called
type?
trees?
list?
AudioGen
@AudioGen
Apr 03 2016 04:30
@RifuI The overall array Object is myPlants
Taur'e Anthony
@k0decraft
Apr 03 2016 04:30
@japyles Thanks again !
CamperBot
@camperbot
Apr 03 2016 04:30
k0decraft sends brownie points to @japyles :sparkles: :thumbsup: :sparkles:
:warning: k0decraft already gave japyles points
Riful
@timburrows
Apr 03 2016 04:31
Yes, I understand this
But what are the words I just listed?
elements in the object?
Chase
@Belax8
Apr 03 2016 04:31
@sudeepnarkar So it would be collection[id] = value; ?
AudioGen
@AudioGen
Apr 03 2016 04:31
@RifuI type is a property of myPlants
Riful
@timburrows
Apr 03 2016 04:31
okay
but why do they all of the sudden not need "" when defined
AudioGen
@AudioGen
Apr 03 2016 04:32
because you are accessing it by the array index
the value is stored in the index
Riful
@timburrows
Apr 03 2016 04:33
so everything between { } is an object
list is an array
and type is just a property/value inside the object
AudioGen
@AudioGen
Apr 03 2016 04:33
@RifuI for this example or in general?
Riful
@timburrows
Apr 03 2016 04:34
for both
AudioGen
@AudioGen
Apr 03 2016 04:34
@RifuI It's actually no to both
Riful
@timburrows
Apr 03 2016 04:34
=/
AudioGen
@AudioGen
Apr 03 2016 04:34
myPlants is the main object
Riful
@timburrows
Apr 03 2016 04:34
I seem to be missing something very important here..
AudioGen
@AudioGen
Apr 03 2016 04:34
@RifuI list is also an object
{ } that can also store the body of functions
@RifuI In many situation in JS, objects are declared outside { } and those store all the properties and their values that correspond with the object
That does make this exercise kind of tricky in a sense but focus more on how to retrieve property values with array indices
Riful
@timburrows
Apr 03 2016 04:37
It just seems like theres a lot going on here unexplained
frustrating =/
I think essentially I'm just getting the brackets confused and whether it is JSON or an object
err JSON or an array
AudioGen
@AudioGen
Apr 03 2016 04:40
@RifuI JSON is a derivative of Javascript, it's not an object, array, or anything like that
Riful
@timburrows
Apr 03 2016 04:41
I see
I think for now I shall just press forward and let things unravel
AudioGen
@AudioGen
Apr 03 2016 04:43
@RifuI Ok Can you type out quick though how you would retrieve the value of an array though?
Riful
@timburrows
Apr 03 2016 04:43
well the answer to that particular exercise was:
```
var secondTree = myPlants[1].list[1];
But if it's just a basic array:
var array = ["example", "example2"];
// array[1] accesses the second index
AudioGen
@AudioGen
Apr 03 2016 04:45
@RifuI So since the array of an index starts at 0 , myPlants is getting the 2nd property type and list is the getting the 2nd value
"trees", "pine"
Riful
@timburrows
Apr 03 2016 04:46
Yup =)
I think I understand fully now.
AudioGen
@AudioGen
Apr 03 2016 04:48
@RifuI That's good, nested arrays are only used so often but definitely make sure you understand arrays in general
Riful
@timburrows
Apr 03 2016 04:48
Well it's not arrays that I don't understand. It's just the specifics of the syntax were confusing me.
Arrays are amongst the most basic data container for any language and JS is not my first language
AudioGen
@AudioGen
Apr 03 2016 04:49
@RifuI Yah
Riful
@timburrows
Apr 03 2016 04:50
But since some of the syntax was unexplained in this exercise it left me with questions , even though I could complete the exercise
This is the first time I've been stopped in my treads so far in the whole course
Rex Smith Jr.
@rsmith731
Apr 03 2016 04:51
does anyone know why so many companies are leaning towards handlebars.js and mustache.js , but still want people know how to code from scratch
Riful
@timburrows
Apr 03 2016 04:51
@AudioGen thanks for your help
CamperBot
@camperbot
Apr 03 2016 04:51
rifui sends brownie points to @audiogen :sparkles: :thumbsup: :sparkles:
:star: 336 | @audiogen | http://www.freecodecamp.com/audiogen
Riful
@timburrows
Apr 03 2016 04:53
That's a very generalized question @rsmith731
Rex Smith Jr.
@rsmith731
Apr 03 2016 04:54
like if they are just using templates anyway, wouldn’t it be easier to just learn how to use them
Riful
@timburrows
Apr 03 2016 04:54
Do you mean to say why should you learnt javascript if you can just use the framework?
Justin
@daemedeor
Apr 03 2016 04:56
@rsmith731 because its a lot more important that if something happened with the framework you can fix it
Rex Smith Jr.
@rsmith731
Apr 03 2016 04:56
@RifuI right
Justin
@daemedeor
Apr 03 2016 04:56
or what if there’s no framework available to do what you want to do?
Rex Smith Jr.
@rsmith731
Apr 03 2016 04:56
@daemedeor ok that makes sense…but does using a template all the time make your skills slack any?
Riful
@timburrows
Apr 03 2016 04:57
@rsmith731 think of templating like not wasting code
Justin
@daemedeor
Apr 03 2016 04:57
well if you know your stuff, it won’t matter
Riful
@timburrows
Apr 03 2016 04:57
it allows you to write something once and use it in many places
handlebars appears to be a framework, like many others, that serve a particular purpose
Justin
@daemedeor
Apr 03 2016 04:57
i like to view templating/using frameworks as … saving time
Riful
@timburrows
Apr 03 2016 04:57
but it doesn't replace javascript
Justin
@daemedeor
Apr 03 2016 04:58
if i can write it and think of it, given enough time… then i don’t feel bad for using a framework
Riful
@timburrows
Apr 03 2016 04:58
and your likely to want to add additional functionality that the framework doesn't provide
Rex Smith Jr.
@rsmith731
Apr 03 2016 05:09
@RifuI gotcha!...
Justin
@daemedeor
Apr 03 2016 05:11
also it pigeonholes you if you only learn frameworks as well @rsmith731
what if the next company you work for doesn’t have x framework?
Riful
@timburrows
Apr 03 2016 05:12
Good point, frameworks don't last forever
nor are they used by all
Justin
@daemedeor
Apr 03 2016 05:12
its easier to pickup frameworks then it is to pickup the underlying logic
asaki444
@asaki444
Apr 03 2016 05:12
hey i need help!
Justin
@daemedeor
Apr 03 2016 05:12
@asaki444 whatcha need help with :D
asaki444
@asaki444
Apr 03 2016 05:14
function convert(num) {
 var romarr = [];
 var newnum = num.toString();
 var length = newnum.length;
 var one = ["I", "II", "III", "IV", "V", "VI","VII", "VIII","IX"];
 var tens = ["X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"];
 var hundred = ["C", "CC","CCC", "CD","D","DCC", "DCCC","CM"];
 var thousand = ["M", "MM", "MMM"];
 var store = function(number){
   var result; 
   if(length > number){
  result = length - number;
}
  else if(length == number){
   result = 0;
  } 
   return result;
 };
 var store2 = new store(2);
 console.log(2);
 romarr.push(one[store]);
 romarr.push(tens[store]);
 romarr.push(hundred[store]);
 romarr.push(thousand[store]);
 return romarr.join("");
}

convert(1200);
I am stuck on this algorithm my object function is not spitting out a result :-/
this is the roman numeral
one!
@daemedeor
Justin
@daemedeor
Apr 03 2016 05:18
@asaki444 errr what would happen if it is less than number?
Gleb
@GlebShaucou
Apr 03 2016 05:35
@camperbot help
Matt Green
@mattxgreen
Apr 03 2016 05:39
@asaki444 you are never calling store()
(with the exception of creating store2, which you never use)
is this: romarr.push(one[store]); supposed to be: romarr.push(one[store()]); ?
and if so, don't you need to pass in a number to store?
asaki444
@asaki444
Apr 03 2016 05:46
@mattxgreen @daemedeor okay guys, I will look into it. I have been working on it. It runs but a few doesn't check out.
 function convert(num) {
 var romarr = [];
 var newnum = num.toString();
 var length = newnum.length;
 var result;
 var pep;
 var sum;
 var one = ["I", "II", "III", "IV", "V", "VI","VII", "VIII","IX"];
 var tens = ["X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"];
 var hundred = ["C", "CC","CCC", "CD","D","DCC", "DCCC","CM"];
 var thousand = ["M", "MM", "MMM"];
 var store = function(number,arr){
   if(length > number){
  result = length - number;
}
  else if(length == number){
   result = 0;
  }
   else {
     result = false;
   }
  pep = newnum[result];
  sum = arr[pep - 1];
  romarr.push(sum);
 };
var store4 = new store(4,thousand);
var store3 = new store(3,hundred);
var store2 = new store(2,tens);
var store1 = new store(1,one);
return romarr.join("");
}

convert(12);
Riful
@timburrows
Apr 03 2016 05:48
I keep typing int when declaring numbers :(
asaki444
@asaki444
Apr 03 2016 05:49
OH it ran
Justin
@daemedeor
Apr 03 2016 06:07
@RifuI wrong language
@asaki444 haha
Riful
@timburrows
Apr 03 2016 06:07
Yup :)
Jeffrey Dinh
@dinhjeffrey
Apr 03 2016 06:32
@RifuI just use var for everything in JS ^_^
Riful
@timburrows
Apr 03 2016 06:32
Force of habit :)
Jeffrey Dinh
@dinhjeffrey
Apr 03 2016 06:32
also const and let, those are ES6 features
Justin
@daemedeor
Apr 03 2016 06:33
i use var for everything, rarely const and even less so let
Jeffrey Dinh
@dinhjeffrey
Apr 03 2016 06:33
if you declare var in loops, it makes it global
because javascript has functional scope but not block scope
Justin
@daemedeor
Apr 03 2016 06:34
ik
but thats when i use let
i didn’t say let was a never case just in frequent
default: var
switch type { case rare: let; const; break; default: var }
;D
i’m just being lazy but you get it
Jeffrey Dinh
@dinhjeffrey
Apr 03 2016 06:36
yeah i keep using var as default too, because of habit haha
Justin
@daemedeor
Apr 03 2016 06:37
i would be careful too mostly because of IE
as always
Edge will update w/ ES but the older IEs won’t really change and have ES5
Bharat
@BharatKalluri
Apr 03 2016 06:38
hey guys! I need a small clarification in counting cards exercise..
How will the input be? will it be in the form of an array?
George Lazar
@geo52dev
Apr 03 2016 06:42
hello folks anyway I could get some help?
Bharat
@BharatKalluri
Apr 03 2016 06:42
Anyone?
George Lazar
@geo52dev
Apr 03 2016 06:43
sure
Bharat
@BharatKalluri
Apr 03 2016 06:43
okay
George Lazar
@geo52dev
Apr 03 2016 06:43
Bharat, I can ask you?
Bharat
@BharatKalluri
Apr 03 2016 06:43
yep
George Lazar
@geo52dev
Apr 03 2016 06:44
OK, thank you here is my syntax

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

// Only change code below this line;

var playerNumber = testObj [16]; // Change this Line
var player = testObj[16];

Fail - playerNumber should be a number
Pass - The variable player should be a string
Pass - The value of player should be "Montana"
Fail - You should use bracket notation to access testObj
Son
@sntruong12
Apr 03 2016 06:46
Hello everyone. I am a JavaScript noobie. Just need an explanation for this.
Bharat
@BharatKalluri
Apr 03 2016 06:47
Can you tell me the q? geo52dev?
Son
@sntruong12
Apr 03 2016 06:47
Screen Shot 2016-04-03 at 1.40.36 AM.png
George Lazar
@geo52dev
Apr 03 2016 06:47
Instructions
Use the playerNumber variable to lookup player 16 in testObj using bracket notation.
Son
@sntruong12
Apr 03 2016 06:49
I don't understand why town still is equal to mark after name was changed to the string "elizabeth". Does this have to do with values and variables?
Bharat
@BharatKalluri
Apr 03 2016 06:50
@geo52dev I think dictionary should have square braackets
George Lazar
@geo52dev
Apr 03 2016 06:50
dictionary?

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

// Only change code below this line;

var playerNumber = testObj[16]; // Change this Line
var player = testObj[16];

Bharat
@BharatKalluri
Apr 03 2016 06:51
@geo52dev yeah.. also called associative arrays
Aleksander Gębicki
@Takumar
Apr 03 2016 06:51
@geo52dev you create variables for a purpose, what is purpose of having playerNumber in your code?
You have two variables player and playerNumber to which you assigned the same value, what for?
George Lazar
@geo52dev
Apr 03 2016 06:52
That's what they supplied
sorry ok
harpoon747
@harpoon747
Apr 03 2016 06:52

Can someone help me with the below code

function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  //return str.substr(str.lastIndexOf(" ")+1);
  if(str.substr(-1,1) === target || str.substr(str.lastIndexOf(" ")+1) === target)
    return true;
  else
    return false;
}

confirmEnding("He has to give me a new name", "name");

It fails for the condition
confirmEnding("He has to give me a new name", "me") should return true.

Aleksander Gębicki
@Takumar
Apr 03 2016 06:53
@geo52dev look at their names and think what you could apply to them. playerNumber maybe it should contain a number?
Justin
@daemedeor
Apr 03 2016 06:54
@geo52dev out of randomness, do you know geology?
George Lazar
@geo52dev
Apr 03 2016 06:54
no daemedeor I don't know geology?
Bharat
@BharatKalluri
Apr 03 2016 06:54
can someone pls help me out....my code
(http://pastebin.com/4k4rzEG0)
George Lazar
@geo52dev
Apr 03 2016 06:54
why?
Aleksander Gębicki
@Takumar
Apr 03 2016 06:55
@harpoon747 a little complicated :-(
If you were said that your string str should begin with target, how would you compare that?
Justin
@daemedeor
Apr 03 2016 06:55
@geo52dev oh i just see geo52
i was curiouss
George Lazar
@geo52dev
Apr 03 2016 06:57
I appreciate curiosity daemedeor but I am really trying to get this code to pass and understand why it does.
Aleksander Gębicki
@Takumar
Apr 03 2016 06:57
@geo52dev my question about variables was because I think that you create variables to use them, so when you create playerNumber variable in your code, you should use it in your code later.
var name = "Peter";
var surname = "Colby";
var fullName = name + " " + surname;
Jackson
@jacksonbrim
Apr 03 2016 06:58
Hi all. I'm pretty stumped on what to do with the Condense arrays with reduce lesson. Any tips?
George Lazar
@geo52dev
Apr 03 2016 06:58
thanks Takumar, I am checking it out
Aleksander Gębicki
@Takumar
Apr 03 2016 06:59
@geo52dev and one more question to ask yourself: testObj[16]; what this statement returns you?
George Lazar
@geo52dev
Apr 03 2016 07:00
It says: playerNumber should be a number
DmytroKurapin
@DmytroKurapin
Apr 03 2016 07:00
Guys! Hello. Help me please to understand how to solve this task ("Seek and Destroy")

function destroyer(arr) {
// Remove all the values
return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

Bharat
@BharatKalluri
Apr 03 2016 07:01
@Takumar Can you please help me out with this code? (http://pastebin.com/4k4rzEG0)
George Lazar
@geo52dev
Apr 03 2016 07:01
I don't know why. Should be an index in an object? Is that possible?
doesn't sound right
Aleksander Gębicki
@Takumar
Apr 03 2016 07:01
@geo52dev :point_up: 3 kwietnia 2016 08:47 you said that instruction states:
  • Use the playerNumber variable to lookup player 16 in testObj using bracket notation.*
Justin
@daemedeor
Apr 03 2016 07:02
@geo52dev are you returning a number?
Jackson
@jacksonbrim
Apr 03 2016 07:02
I'm stuck on this Condense Arrays With Reduce. I feel like the instructions are a little unclear as to how to use the "Reduce" method.
George Lazar
@geo52dev
Apr 03 2016 07:03
@daemedeor yes, but I don't know how to get to it the second time
Aleksander Gębicki
@Takumar
Apr 03 2016 07:03
@geo52dev player should contain player's name I think which you get from your object, playerNumber is a number. Right?
@Bharat-Kalluri at first look your code looks good, but I used switch() case ... for that, I will look again at it.
@Bharat-Kalluri oh, wait. card is a single value, you shouldn't use loop for this challenge,
In your conditions you should check card value not indexes of loop!
George Lazar
@geo52dev
Apr 03 2016 07:06
@Takumar here what I did: var player = testObj[16];
Aleksander Gębicki
@Takumar
Apr 03 2016 07:06
@geo52dev almost good, but you still haven't used playerNumber variable, right?
What you assigned to playerNumber variable?
George Lazar
@geo52dev
Apr 03 2016 07:07
correct, that where my problem lies
Bharat
@BharatKalluri
Apr 03 2016 07:07
@Takumar Finally! thanks for the reply! But sorry, I was not able to understand what you were saying.
CamperBot
@camperbot
Apr 03 2016 07:07
bharat-kalluri sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star: 2973 | @takumar | http://www.freecodecamp.com/takumar
Aleksander Gębicki
@Takumar
Apr 03 2016 07:08
@Bharat-Kalluri you've created a loop, but card variable is a single value which represents single card.
Instruction for this challenge is not clear I think.
George Lazar
@geo52dev
Apr 03 2016 07:09
@Takumar I don't know how to access the player number in bracket notation from this object
I am accessing the key value but not the property
Bharat
@BharatKalluri
Apr 03 2016 07:10
@Takumar sadly, yes. If i remove the for loop , will it work?
Aleksander Gębicki
@Takumar
Apr 03 2016 07:10
@geo52dev var player = testObj[16]; - with that line, you accessed key 16 in testObj object, so you found name (value) of player which has number 16.
I think you should assign 16 to playerNumber and later use it instead of writing 16 in brackets in this line: var player = testObj[16];
That's all :-)

@Bharat-Kalluri remove loop and correct all conditions.
Look at your code:

  for(i=0;i<card.length;i++) {
    if (i == 2 || i == 3 || i == 4 || i == 5 || i == 6) {

remove loop, and check card value:

if (card === 2 || card === 3...
George Lazar
@geo52dev
Apr 03 2016 07:12
what about playerNumber? That is where I am having my problem.
Aleksander Gębicki
@Takumar
Apr 03 2016 07:12
@geo52dev read this again :point_up: 3 kwietnia 2016 09:10
George Lazar
@geo52dev
Apr 03 2016 07:12
@Takumar ok
Aleksander Gębicki
@Takumar
Apr 03 2016 07:14
@geo52dev var player = testObj[16]; this is good, but what your code would do when I want to get name of player number 17? And a second later 8?
Your function should use parameters, variables to be flexible, to answer many questions when run with different arguments.
And that's where playerNumber comes, you assign it number of player, and second line gets this player's name from your object (team). :fireworks:
harpoon747
@harpoon747
Apr 03 2016 07:16
@Takumar Yep over complicated things there .. fixed now ! Thank you
Aleksander Gębicki
@Takumar
Apr 03 2016 07:18
@harpoon747 you haven't answered my question, I hope it helped you. I just wanted to say you that you can compare string at the beginning the same way you can do with substring at the end you just have to use negative indexes. str.substr(-target.length)
Riful
@timburrows
Apr 03 2016 07:19
For this exercise, am I supposed to use a for loop?
//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

// Only change code above this line
}

// Change these values to test your function
lookUp("Akira", "likes");
Bharat
@BharatKalluri
Apr 03 2016 07:21
@Takumar That solved it! Thanks!
CamperBot
@camperbot
Apr 03 2016 07:21
bharat-kalluri sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:warning: bharat-kalluri already gave takumar points
Aleksander Gębicki
@Takumar
Apr 03 2016 07:22
@Bharat-Kalluri good job :thumbsup: :-)
@RifuI yes I think so, you have to check every contact in your array, so loop will be needed.
George Lazar
@geo52dev
Apr 03 2016 07:23
@Takumar here are the instructions of the exercise: Instructions
Use the playerNumber variable to lookup player 16 in testObj using bracket notation.
Riful
@timburrows
Apr 03 2016 07:23
Ta, i was just wondering if javascript had some fancy built-in way of doing that
Aleksander Gębicki
@Takumar
Apr 03 2016 07:24
@geo52dev yes, use playerNumber in testObj using bracket notation :-)
George Lazar
@geo52dev
Apr 03 2016 07:25
var playerNumber = testObj[16]; this is not bracket notation?
Aleksander Gębicki
@Takumar
Apr 03 2016 07:25
@RifuI I don't know such method, even if it exists :-)
It is basic array.
@geo52dev yes, there is bracket notation but where do you see playerNumber - not player number it should be playerNumber variable!
Riful
@timburrows
Apr 03 2016 07:26
Sorry, maybe it was a dumb question
Markus Kiili
@Masd925
Apr 03 2016 07:26
@RifuI You can use for loop or array iterator method.
Aleksander Gębicki
@Takumar
Apr 03 2016 07:26
@RifuI not dumb, @Masd925 will tell you how to do this in one line :-)
Hi @Masd925
Riful
@timburrows
Apr 03 2016 07:27
haha
Markus Kiili
@Masd925
Apr 03 2016 07:27
@Takumar Good morning.
Aleksander Gębicki
@Takumar
Apr 03 2016 07:27
@RifuI someone else may come and tell that in ES6 you can use spread operator or some new crazy stuff :-)
George Lazar
@geo52dev
Apr 03 2016 07:31
@Takumar: I see playerNumber as the second property of the testObj object.
Aleksander Gębicki
@Takumar
Apr 03 2016 07:31
@Masd925 you are not angry with that joke? I didn't mean to offend you.
Riful
@timburrows
Apr 03 2016 07:32
I think it was fine Takumar
Aleksander Gębicki
@Takumar
Apr 03 2016 07:34

@geo52dev your's code:

// Setup
var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
// Only change code below this line;
var playerNumber = testObj[16]; // Change this Line
var player = testObj[16];

You have testObj object here with three "property:value" pairs.
As result of your exercise you should get "Montana" in player variable.

George Lazar
@geo52dev
Apr 03 2016 07:34
var playerNumber = player; // Change this Line
var player = testObj[16];
Jackson
@jacksonbrim
Apr 03 2016 07:34
Would anybody mind helping me? I am having a bit of trouble with a Javascript Lesson or is it called a bonfire?
CamperBot
@camperbot
Apr 03 2016 07:34
type bonfire name to get some info on that bonfire. And check HelpBonfires chatroom
Aleksander Gębicki
@Takumar
Apr 03 2016 07:34
@geo52dev no, start from var playerNumber = 16; and use it in second line!
George Lazar
@geo52dev
Apr 03 2016 07:35
it does... I am returning Montana
Jackson
@jacksonbrim
Apr 03 2016 07:35
bonfire name
CamperBot
@camperbot
Apr 03 2016 07:35
Sorry, can't find a bonfire called name. [ Check the map? ]
Jackson
@jacksonbrim
Apr 03 2016 07:35
Condense arrays with .reduce
Markus Kiili
@Masd925
Apr 03 2016 07:35
@Takumar No. The functional solution with .reduce() is actually very elegant. And in one line.
Jackson
@jacksonbrim
Apr 03 2016 07:35
bonfire Condense arrays with .reduce
CamperBot
@camperbot
Apr 03 2016 07:35
Sorry, can't find a bonfire called condense arrays with reduce. [ Check the map? ]
Aleksander Gębicki
@Takumar
Apr 03 2016 07:35
@Masd925 I knew this :-) (that you have one liner in your pocket)
Jackson
@jacksonbrim
Apr 03 2016 07:36
bonfire Condense arrays with reduce
CamperBot
@camperbot
Apr 03 2016 07:36
Sorry, can't find a bonfire called condense arrays with reduce. [ Check the map? ]
George Lazar
@geo52dev
Apr 03 2016 07:37
Thanks @Takumar
var playerNumber = 16; // Change this Line
var player = testObj[16];
but it is still telling me by bracket notation to access testObj
CamperBot
@camperbot
Apr 03 2016 07:37
geo52dev sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star: 2974 | @takumar | http://www.freecodecamp.com/takumar
Aleksander Gębicki
@Takumar
Apr 03 2016 07:38

@geo52dev I don't know how to explain it to you I meant:

var player = testObj[playerNumber];

that's all. Without it, you don't use playerNumber anywhere after assigning it number 16. So what for creating such variable?

Markus Kiili
@Masd925
Apr 03 2016 07:39
@Takumar I have to code more in the spirit of clean code standards at work, so these one-liners are a good counterpoise.
George Lazar
@geo52dev
Apr 03 2016 07:39
That worked Takumar much thanks but I don't fully understand it
Riful
@timburrows
Apr 03 2016 07:39
+1 for clean code.
Jackson
@jacksonbrim
Apr 03 2016 07:39
Is this not the right place to post for help with lessons?
George Lazar
@geo52dev
Apr 03 2016 07:39
I am going to go back over and the stuff and review
Riful
@timburrows
Apr 03 2016 07:40
It's the right place jackson
I'm not sure what a bonfire is, I may not be up to that yet.
George Lazar
@geo52dev
Apr 03 2016 07:40
I don't understand how playerNumber became a property of the tesObj
Riful
@timburrows
Apr 03 2016 07:41
@geo52dev playerNumber is not a properly, it is a variable that you assigned the number 16 to.
Markus Kiili
@Masd925
Apr 03 2016 07:41
@geo52dev playerNumber is a variable that contains the property key.
Riful
@timburrows
Apr 03 2016 07:41
testObj[16] accesses the 16th element in the array.
testObj[playerNumber] will also access the 16th element in the array.
Aleksander Gębicki
@Takumar
Apr 03 2016 07:42
@RifuI it's not index, it is name of property. testObj is object which has 3 properties: 12, 16 and 19
Jackson
@jacksonbrim
Apr 03 2016 07:42
Nevermind
Riful
@timburrows
Apr 03 2016 07:42
Oh sorry, I didn't read the whole thing
George Lazar
@geo52dev
Apr 03 2016 07:42
thanks @RifuI
CamperBot
@camperbot
Apr 03 2016 07:42
geo52dev sends brownie points to @rifui :sparkles: :thumbsup: :sparkles:
:star: 229 | @rifui | http://www.freecodecamp.com/rifui
Jackson
@jacksonbrim
Apr 03 2016 07:43
I found the freecodecamp wiki. If anybody else needs it for lack of help, you can go here: https://github.com/freecodecamp/freecodecamp/wiki
Riful
@timburrows
Apr 03 2016 07:44
That's nice, I didn't know that existed.
lockee14
@lockee14
Apr 03 2016 07:44
hi freecode
George Lazar
@geo52dev
Apr 03 2016 07:44
Is there a way to grab all the text from our chats?
lockee14
@lockee14
Apr 03 2016 07:45
i dont understand why my code dont work...
$(document).ready(function() {

  var url = "https://en.wikipedia.org/w/api.php?action=query&format=json&prop=info&titles=Albert+Einstein";
  $.getJSON(url, function(json) {
    $("#test").html(JSON.stringify(json));
  });



});
George Lazar
@geo52dev
Apr 03 2016 07:46
@Takumar thank you I really appreciated your help
CamperBot
@camperbot
Apr 03 2016 07:46
geo52dev sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:warning: geo52dev already gave takumar points
lockee14
@lockee14
Apr 03 2016 07:46
it dont print me the json object on the page... i dont know why
Markus Kiili
@Masd925
Apr 03 2016 07:49
@jacksonbrim If you have a question about an exercise, just post the question. Usually someone helps.
lockee14
@lockee14
Apr 03 2016 07:52
; (
Olawale Akinseye
@brainyfarm
Apr 03 2016 07:53
@lockee14, your problem is most likely with cross origin issues.
Try http://crossorigin.me/https://en.wikipedia.org/w/api.php?action=query&format=json&prop=info&titles=Albert+Einstein as your request url and if it works then you can look into JSONP or circumvent it with crossorigin.me.
I am on mobile at the moment but I suspect that is the issue you have.
@lockee14
lockee14
@lockee14
Apr 03 2016 07:56
thx @brainyfarm it work O_o
Olawale Akinseye
@brainyfarm
Apr 03 2016 07:58
@lockee14, try to use the developer tool while coding to help you debug faster and understand where you are wrong. For problems like this one, I would recommend Firebug on Firefox.
lockee14
@lockee14
Apr 03 2016 08:00
ok, i usually use chrome
Olawale Akinseye
@brainyfarm
Apr 03 2016 08:00
Chrome has the developer tool as well.
Rithvik Vibhu
@rithvikvibhu
Apr 03 2016 08:01
Hey ppl. Is "ate" a NaN?
tjhpae
@tjhpae
Apr 03 2016 08:01
good evening ya'll
Justin
@daemedeor
Apr 03 2016 08:01
@rithvikvibhu yes
tjhpae
@tjhpae
Apr 03 2016 08:01
can anyone tell me why this wouldn't work?

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

// Only change code below this line;

var playerNumber = testObj[16]; // Change this Line
var player = testObj.playernumber;

Justin
@daemedeor
Apr 03 2016 08:01
Not a Number @rithvikvibhu
haha
the first 2 requirements need the function to return "ate" and "a" but the next 2 ones require NaN to be removed
Olawale Akinseye
@brainyfarm
Apr 03 2016 08:03
@tjhpae, first, you are referencing the wrong variable name and you should use the bracket notation on your last line.
Bogdan3
@Bogdan3
Apr 03 2016 08:03

Hello i'm working on the "Repeat a string repeat a string" challenge and its always gives me undefined and what should return ("undefinedabcabcabc").```
function repeatStringNumTimes(str, num) {
while( num >0){
var rStr;
rStr = rStr + str;
num--;
}
return rStr;
}

repeatStringNumTimes("abc", 3);
```

Riful
@timburrows
Apr 03 2016 08:04

Okay I'm really confused, is this a bug?

function lookUp(firstName, prop){

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

    } 
  }
}

This ticks all the boxes, returning the correct values

Rithvik Vibhu
@rithvikvibhu
Apr 03 2016 08:04
@Bogdan3 change var rStr; to var rStr="";
tjhpae
@tjhpae
Apr 03 2016 08:04

@brainyfarm if i just ran

var playerNumber = testObj[16]

wouldn't this give me 'Montana'?

Justin
@daemedeor
Apr 03 2016 08:04
@rithvikvibhu looking at the code on moment
tjhpae
@tjhpae
Apr 03 2016 08:04
from var testObj?
Riful
@timburrows
Apr 03 2016 08:04
But it won't pass the tests when I add an else statement
Justin
@daemedeor
Apr 03 2016 08:05
@rithvikvibhu well you need to coerce “ate” to a NaN so IsNaN(parseInt(“ate”))
Olawale Akinseye
@brainyfarm
Apr 03 2016 08:05
@Bogdan3, at the first iteration rStr = rStr + str; remember rStr would be undefined.
Riful
@timburrows
Apr 03 2016 08:05
I think i posted the wrong thing.
Olawale Akinseye
@brainyfarm
Apr 03 2016 08:06
So you are adding undefined as the first character @Bogdan3.
Justin
@daemedeor
Apr 03 2016 08:06
@rithvikvibhu i thought you tried to convert it to an interger first haha
Rithvik Vibhu
@rithvikvibhu
Apr 03 2016 08:06
@daemedeor but "ate" isnt an int
Justin
@daemedeor
Apr 03 2016 08:07
@rithvikvibhu but its a string value
its NAN
Martialis39
@Martialis39
Apr 03 2016 08:08
Hey guys, could use your help with Nested For Loops
Riful
@timburrows
Apr 03 2016 08:08
Ask away Martialis
Justin
@daemedeor
Apr 03 2016 08:08
after you coerce @rithvikvibhu
Vivek
@vivek28111992
Apr 03 2016 08:08
@Martialis39 sure
Martialis39
@Martialis39
Apr 03 2016 08:09
Trying to copy paste :D one second
Olawale Akinseye
@brainyfarm
Apr 03 2016 08:09
@tjhpae, your playerNumber value should be an integer, you use the bracket notation to test for that property on the next line.
Martialis39
@Martialis39
Apr 03 2016 08:09
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for(var i=0; i < arr.length; i++) {
    for( var j=0; j < arr[i].length; j++){

      product = arr[i][j] * arr[i][j+1];
      return product;

    }
  }
Rithvik Vibhu
@rithvikvibhu
Apr 03 2016 08:09
@daemedeor isNaN(parseInt(val)) gives false i guess because its not part of result
Martialis39
@Martialis39
Apr 03 2016 08:09
Ok, soI think this is how it should work but it isn\t working
also I missed another return statement that is outside the 2 loops in the copy-paste
Riful
@timburrows
Apr 03 2016 08:10
Try using:
Bogdan3
@Bogdan3
Apr 03 2016 08:10
i defined rStr but now is giving me just abc @brainyfarm @rithvikvibhu
Riful
@timburrows
Apr 03 2016 08:10
product *= arr[i][j];
Justin
@daemedeor
Apr 03 2016 08:10
@rithvikvibhu might have misspelled that parseInt i always forget about that
Rithvik Vibhu
@rithvikvibhu
Apr 03 2016 08:10
isNaN(parseInt(val))
Olawale Akinseye
@brainyfarm
Apr 03 2016 08:10
@Martialis39 you also should not return product inside the for loop.
Riful
@timburrows
Apr 03 2016 08:10
So:
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;
}
Rithvik Vibhu
@rithvikvibhu
Apr 03 2016 08:10
seems right
Martialis39
@Martialis39
Apr 03 2016 08:11
@RifuI @brainyfarm Thank you! Sure enough ,that did it!
CamperBot
@camperbot
Apr 03 2016 08:11
martialis39 sends brownie points to @rifui and @brainyfarm :sparkles: :thumbsup: :sparkles:
:star: 1747 | @brainyfarm | http://www.freecodecamp.com/brainyfarm
:star: 230 | @rifui | http://www.freecodecamp.com/rifui
Olawale Akinseye
@brainyfarm
Apr 03 2016 08:11
@RifuI, no need to post solutions man :D
Riful
@timburrows
Apr 03 2016 08:11
@brainyfarm is correct, if you return inside the for loop it will not continue on to the next iteration afterwards
Martialis39
@Martialis39
Apr 03 2016 08:11
Could help me explain \ product *= \ syntax?
I tried it before without the return at the end but still couldnt get anywhere
Olawale Akinseye
@brainyfarm
Apr 03 2016 08:11
@Bogdan3, kindly post your code again.
Riful
@timburrows
Apr 03 2016 08:12
@Martialis39 It is the same as writing product = product * x;
Martialis39
@Martialis39
Apr 03 2016 08:12
Right!
Riful
@timburrows
Apr 03 2016 08:12
@Martialis39 instead you write product *= x;
tjhpae
@tjhpae
Apr 03 2016 08:12
@brainyfarm just so i understand this conceptually, why does this return an error?

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

// Only change code below this line;
testObj.12;

Martialis39
@Martialis39
Apr 03 2016 08:12
so product get multiplied by 1st value, then that value is assigned to product, and then rinse and repeat?
Bogdan3
@Bogdan3
Apr 03 2016 08:13

function repeatStringNumTimes(str, num) {
while( num >0){
var rStr="";
rStr += str;
num--;
}
return rStr;
}

repeatStringNumTimes("abc", 3);
@brainyfarm

Riful
@timburrows
Apr 03 2016 08:13
@Martialis39 correct
Think of it as appending the results of your maths onto the original value.
Markus Kiili
@Masd925
Apr 03 2016 08:14
@tjhpae "12" is not a valid JS identifier, so you cannot use dot notation.
Olawale Akinseye
@brainyfarm
Apr 03 2016 08:14
@tjhpae the code is not yet complete and you cannot test with the dot notation since 12 is not a valid js identifier so use the bracket notation instead.
Martialis39
@Martialis39
Apr 03 2016 08:14
@RifuI Good, thanks again! I think I understand :D
CamperBot
@camperbot
Apr 03 2016 08:14
martialis39 sends brownie points to @rifui :sparkles: :thumbsup: :sparkles:
:warning: martialis39 already gave rifui points
Riful
@timburrows
Apr 03 2016 08:15
No problem, and sorry for posting the solution. It was just that you were so close and I thought that would be easiest.
Olawale Akinseye
@brainyfarm
Apr 03 2016 08:15
What result are you getting @Bogdan3?
Bogdan3
@Bogdan3
Apr 03 2016 08:16
just abc @brainyfarm
Riful
@timburrows
Apr 03 2016 08:17

Could someone please explain what is wrong with this?

function lookUp(firstName, prop){

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

      return contacts[i][prop];
    }
    else {
      return "No such contact";
    }


  }
}

I get "No such contact" even if the contact exists. When I remove the else, the contact is returned as you would expect. Exercise "Profile Lookup"

Martialis39
@Martialis39
Apr 03 2016 08:17
@RifuI I think its right you did (but ofcourse I would say that), I felt like I ''got it'' but couldnt make the code do my bidding.
Olawale Akinseye
@brainyfarm
Apr 03 2016 08:17
@Bogdan3, now move the declaration of rStr outside of the loop.
James Bond
@Dman89
Apr 03 2016 08:18
anyone got time to look at my btns
see why they wwont work?
Olawale Akinseye
@brainyfarm
Apr 03 2016 08:18
@Bogdan3 remember, you are declaring the variable again and setting it to "" at every iteration.
Bogdan3
@Bogdan3
Apr 03 2016 08:19
now is working thanks @brainyfarm
CamperBot
@camperbot
Apr 03 2016 08:19
bogdan3 sends brownie points to @brainyfarm :sparkles: :thumbsup: :sparkles:
:star: 1748 | @brainyfarm | http://www.freecodecamp.com/brainyfarm
Markus Kiili
@Masd925
Apr 03 2016 08:19
@RifuI Returning no such contact should be after contact loop block.
Riful
@timburrows
Apr 03 2016 08:20
omg are you kidding me lol
Rithvik Vibhu
@rithvikvibhu
Apr 03 2016 08:20
@daemedeor Got it working with .filter(Boolean) (removing the whole function) Thanks anyway
CamperBot
@camperbot
Apr 03 2016 08:20
rithvikvibhu sends brownie points to @daemedeor :sparkles: :thumbsup: :sparkles:
:star: 157 | @daemedeor | http://www.freecodecamp.com/daemedeor
Riful
@timburrows
Apr 03 2016 08:20
No that makes total sense, thanks @Masd925
CamperBot
@camperbot
Apr 03 2016 08:20
rifui sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1279 | @masd925 | http://www.freecodecamp.com/masd925
Justin
@daemedeor
Apr 03 2016 08:20
@rithvikvibhu congrats. i didn’t want to tell you the answer XD
that what you had it could be so much easier
haha
Andrew McKeever
@andmckvr13
Apr 03 2016 08:32
This message was deleted
function palindrome(str) {
  // Good luck!
  var palindrome;
  str.toLowerCase().replace(/\W/, str);
  palindrome = str.split('').reverse().join('');

  if (str == palindrome) {
    return true;
  } else if (str !== palindrome) {
    return false;
  }
  else {
    return false;
  }


}



palindrome("not a plaindrome");
Riful
@timburrows
Apr 03 2016 08:33
@Dman89 did you chrome inspector is saying there is an error on line 27, did you check that out?
Andrew McKeever
@andmckvr13
Apr 03 2016 08:33
anyone have an idea why this code isnt working? I just keep getting false
Markus Kiili
@Masd925
Apr 03 2016 08:33
@andmckvr13 You are not removing underscore.
James Bond
@Dman89
Apr 03 2016 08:34
@RifuI resaved, will u check again real quick
Riful
@timburrows
Apr 03 2016 08:34
sure
Markus Kiili
@Masd925
Apr 03 2016 08:34
@andmckvr13 Strings are immutable, so str.toLowerCase... does nothing.
Andrew McKeever
@andmckvr13
Apr 03 2016 08:34
for underscore its just /\W_/ correct?
Markus Kiili
@Masd925
Apr 03 2016 08:35
@andmckvr13 Sot sure, but with [ ] it works.
James Bond
@Dman89
Apr 03 2016 08:35
@RifuI i got it i think, thank you
CamperBot
@camperbot
Apr 03 2016 08:35
dman89 sends brownie points to @rifui :sparkles: :thumbsup: :sparkles:
:star: 232 | @rifui | http://www.freecodecamp.com/rifui
Justin
@daemedeor
Apr 03 2016 08:35
@andmckvr13 it is but you need to look for a group, regex isn’t constructed like that haha
Markus Kiili
@Masd925
Apr 03 2016 08:35
@andmckvr13 Instead of if-elses, you can just return str===palindrome;.
Riful
@timburrows
Apr 03 2016 08:36
Yeah it's working for me ^^
I was thinking umm.. what's wrong with it? lol
Andrew McKeever
@andmckvr13
Apr 03 2016 08:37
@RifuI my code is working for you?
Riful
@timburrows
Apr 03 2016 08:37
Sorry @andmckvr13 I was talking to Dman89
James Bond
@Dman89
Apr 03 2016 08:38
@RifuI i fixed it up a lil, how come my css doesnt follow with .innerHTML
Andrew McKeever
@andmckvr13
Apr 03 2016 08:38
@Masd925 @daemedeor thanks
CamperBot
@camperbot
Apr 03 2016 08:38
andmckvr13 sends brownie points to @masd925 and @daemedeor :sparkles: :thumbsup: :sparkles:
:star: 1280 | @masd925 | http://www.freecodecamp.com/masd925
:star: 158 | @daemedeor | http://www.freecodecamp.com/daemedeor
Andrew McKeever
@andmckvr13
Apr 03 2016 08:39
@daemedeor what do you mean by group?
Olawale Akinseye
@brainyfarm
Apr 03 2016 08:39
@Masd925 str.toLowerCase() does nothing?
Justin
@daemedeor
Apr 03 2016 08:39
@andmckvr13 more like \(\W_)\gi
Markus Kiili
@Masd925
Apr 03 2016 08:39
@brainyfarm If you don't assign the returned value, it does nothing. Strings are immutable.
James Bond
@Dman89
Apr 03 2016 08:40
@RifuI nvm found it
<#
<3
Riful
@timburrows
Apr 03 2016 08:40
Let me help you! =(
haha
I'm glad you got it.
Justin
@daemedeor
Apr 03 2016 08:42
@andmckvr13 wait sorry, this is the regx you want \[\W_]+\gi
keep mixing the two XD
Jonathan Bennett
@jonathanabennett
Apr 03 2016 08:43
I'm a bit confused by the "Generate Random Whole Numbers with JavaScript" challenge. Here's my code:

var randomNumberBetween0and19 = Math.floor(Math.random() * 20);

function myFunction() {

// Only change code below this line.
var randomNum = Math.random() * 10;

return Math.floor(randomNum);
}

It returns a random number between 0 and 9 every time. It's whole. But the page tells me that I'm failing the "You should have multipled the result of Math.random by 10 to make it a number that is between 0 and 9.
Thomas Hennes
@jaxxeh
Apr 03 2016 08:44
@daemedeor you don't need the + part if you're using the g modifier, it's already looking for multiple matches
Olawale Akinseye
@brainyfarm
Apr 03 2016 08:44
I understand that now @Masd925, sorry for that. I just looked at his code again. Thanks for clarification, I interpreted that out of context.
CamperBot
@camperbot
Apr 03 2016 08:44
brainyfarm sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1281 | @masd925 | http://www.freecodecamp.com/masd925
Jonathan Bennett
@jonathanabennett
Apr 03 2016 08:46
What am I doing wrong on this?
Justin
@daemedeor
Apr 03 2016 08:46
@jaxxeh meh i’m not in the business of making the regex the most performant
i use regex so little XD
Jonathan Bennett
@jonathanabennett
Apr 03 2016 08:46
Is there some JavaScript pattern/formula that I'm missing?
Riful
@timburrows
Apr 03 2016 08:46
@jonathanabennett You should use the function name that is provided so that the unit tests can validate your code.
Also your algorithm is not quite right, the exercise shows you the formula.
Jonathan Bennett
@jonathanabennett
Apr 03 2016 08:48
I found it. It needed to be a one-liner, I guess. That's the only thing I changed.
Riful
@timburrows
Apr 03 2016 08:48
return on the same line?
Jonathan Bennett
@jonathanabennett
Apr 03 2016 08:49
yeah
return Math.floor(Math.random() * 10))
Riful
@timburrows
Apr 03 2016 08:50
Yeah sometimes you have to obide by their unit tests and that is n't always clear how to do that
p.s i'm up to the same exercise as you :)
Jonathan Bennett
@jonathanabennett
Apr 03 2016 08:58
Regex are coming soon. They're like winter, except they kill more people.
Pete
@petegarvin1
Apr 03 2016 08:58
@jonathanabennett :D
Jonathan Bennett
@jonathanabennett
Apr 03 2016 08:58
Some people have a problem and think, "I know, I'll use a Regex!" Now, they have two problems.
In my python programming experience, I did literally everything possible to avoid them. Literally.
Justin
@daemedeor
Apr 03 2016 08:59
i still avoid regex myself
Pete
@petegarvin1
Apr 03 2016 08:59
I'm trying to love regex... but i think it hates me
it barely accepts my calls
Justin
@daemedeor
Apr 03 2016 09:00
i’ll use regex if the case is abudantly clear to use it, but its not really great for performance to begin with
Jonathan Bennett
@jonathanabennett
Apr 03 2016 09:01
Yeah. Any time, I hit a regex, I always ask myself "Is there something I can change in my data that eliminates this regex?"
that must be hell then
Jonathan Bennett
@jonathanabennett
Apr 03 2016 09:05
If it isn't hell itself, it's definitely in the same zip code.
Justin
@daemedeor
Apr 03 2016 09:05
lol
@jonathanabennett and here’s a sample of what you are talking about: http://imgs.xkcd.com/comics/perl_problems.png
xkcd <3 :D
Martialis39
@Martialis39
Apr 03 2016 09:13
Hey guys, just a quick question; On profile look-up, my if statement doesn't work with if (firstName === contacts[i][firstName]) but does work if I use dot notation for .firstName, why is that?
Justin
@daemedeor
Apr 03 2016 09:13
@Martialis39 because you’re passing in a variable
if (firstName === contacts[i]["firstName"])
is what you’re looking for
Martialis39
@Martialis39
Apr 03 2016 09:15
Ok
I think I understand :)
I eventually got through but one solution I think was a bit hacky and unelegant
Elbert Cortez
@trip16661
Apr 03 2016 09:15
@daemedeor Do you know any way to filter two parameters ?(like 2 properties)
Justin
@daemedeor
Apr 03 2016 09:15
@Martialis39 sometimes you do what you have to do to get it done
@trip16661 at a time?
Elbert Cortez
@trip16661
Apr 03 2016 09:16
y
Justin
@daemedeor
Apr 03 2016 09:16
@trip16661 two different tests?
Elbert Cortez
@trip16661
Apr 03 2016 09:16
yes
Justin
@daemedeor
Apr 03 2016 09:16
you’ll have to be a little more specific
by how do you mean “filter"
Elbert Cortez
@trip16661
Apr 03 2016 09:16
let me show you
lol codepen failed xDD
Jonathan Bennett
@jonathanabennett
Apr 03 2016 09:17
@Martialis39 It's tricky because firstName is both a property in the contacts variable and a variable in the function you're working on. It can create a namespace collision in your brain if you aren't careful.
Elbert Cortez
@trip16661
Apr 03 2016 09:17
it just crashed f**k.. i hope it saved it xD
Justin
@daemedeor
Apr 03 2016 09:17
lol
saving is important!
@jonathanabennett hence the quotations
;D
Martialis39
@Martialis39
Apr 03 2016 09:17
@jonathanabennett I think that's exactly what has happened :D
Elbert Cortez
@trip16661
Apr 03 2016 09:18
@daemedeor good bless auto saving
var api = "https://crossorigin.me/http://api.forismatic.com/api/1.0/?method=getQuote";

var format = "&format=json";
var lang = "&lang=en";

$(document).ready(function() {
  $("#submit").on("click", function() {
    function keyCode() {
      return Math.floor(Math.random() * 1000000);

    };
    var randomNum = keyCode();
    var key = '&key=' + randomNum;
    var apiLink = api + key + format + lang;

    $.getJSON(apiLink, function(quoteData) {
      quoteData = quoteData.filter(function (val) {
           return (val.hasOwnProperty(quoteText))&&(val.hasOwnProperty(quoteAuthor));

       });   
      var quote = ""; 
      var keys = Object.keys(quoteData);

      keys.forEach(function(keysValu) {

          quote += "<b>"+keysValu+"</b></br>"+quoteData[keysValu];

      }); 
      $("#wiseWords").html(quote);
    });

  });
});
quoteData,filter
Justin
@daemedeor
Apr 03 2016 09:19
that looks right
Elbert Cortez
@trip16661
Apr 03 2016 09:19
i tried in this way a noob way to do it
but it don't work anymore
Justin
@daemedeor
Apr 03 2016 09:19
i don’t know what quoteText or quoteAuthor is
Elbert Cortez
@trip16661
Apr 03 2016 09:19
is the value i want to keep
and delete everything else
Justin
@daemedeor
Apr 03 2016 09:20
why not just make a new object?
Elbert Cortez
@trip16661
Apr 03 2016 09:20
properties*
cuz i hate my life and i like to make it harder D:
i didn't thought of it xD
but now that i'm on is there any way?
Justin
@daemedeor
Apr 03 2016 09:21
is quoteText the value?
Elbert Cortez
@trip16661
Apr 03 2016 09:22
quoteText is the property that i want to keep
same as quoteAuthor
Justin
@daemedeor
Apr 03 2016 09:22
and the author is another property?
are you sure?
Elbert Cortez
@trip16661
Apr 03 2016 09:22
yes
Justin
@daemedeor
Apr 03 2016 09:22
you want to change that to OR
(val.hasOwnProperty(quoteText))||(val.hasOwnProperty(quoteAuthor));
you’ll never have a property be both the text and the author
i’m fairly sure
Elbert Cortez
@trip16661
Apr 03 2016 09:25
I want to filter the two
Justin
@daemedeor
Apr 03 2016 09:25
yea
@trip16661 but what i’m saying is if you say or it either has to have the quoteText property or the quoteAuthor property
@trip16661 i’m assumign quoteTxt and quoteAuthor are suppsoed to be variables … right?
Elbert Cortez
@trip16661
Apr 03 2016 09:27
no there are properties of an object
i want to keep the object
but delete any information aside from quoteText and quoteAuthor
Justin
@daemedeor
Apr 03 2016 09:28
@trip16661 oooh then you have to make those into strings
(val.hasOwnProperty(“quoteText"))||(val.hasOwnProperty(“quoteAuthor"));
but what you’re doing here is basically seeing if it has quotetext or quoteauthor
so… it wouldn’t filter if everything has it
so a better way
is to literally just go through each one
and then get those properties and values
:D
since you know the name of the property
Elbert Cortez
@trip16661
Apr 03 2016 09:31
D:
I see
thanks @daemedeor
CamperBot
@camperbot
Apr 03 2016 09:31
trip16661 sends brownie points to @daemedeor :sparkles: :thumbsup: :sparkles:
:star: 161 | @daemedeor | http://www.freecodecamp.com/daemedeor
Justin
@daemedeor
Apr 03 2016 09:32
or you can go for ( var property in object) { if(property == “quoteText” || property == “quoteAuthor”) { });@trip16661
basically going through each property in a single object and just grabs the relevant proeprties
i’ll leave the actual better implemenation to you
Dave Melia
@Dave-Melia
Apr 03 2016 09:35
Hey guys, how can I compare every array index with each other? for example, having an array [1, 2, 3, 5, 6, 3, 1, 9, 5], how can I compare index 0, to the 1st index, then the second, then the 3rd and so on, then compare the 1st index with 0, 2, 3, 4, 5, etc. I know I need to use nested for-loops, but I can't figure out the logic
Riful
@timburrows
Apr 03 2016 09:35
You can use index+1 inside the for loop.
Justin
@daemedeor
Apr 03 2016 09:35
@Dave-Melia well if you want to continue with nested for loops, you know which index right?
you’re currently on
Dave Melia
@Dave-Melia
Apr 03 2016 09:36
@RifuI how do you mean?
Justin
@daemedeor
Apr 03 2016 09:36
so you can skip the one you’re on
Dave Melia
@Dave-Melia
Apr 03 2016 09:36
@daemedeor I don't understand
Justin
@daemedeor
Apr 03 2016 09:37
for(var i = 0; i < array.length; i ++){ for(var j = i + 1; j< array.length; j++){}}
is what riful was talking about
Dave Melia
@Dave-Melia
Apr 03 2016 09:37
I tried that, does it work?
will i = 0, and j = 1,2,3,4...length?
Justin
@daemedeor
Apr 03 2016 09:37
for(var i = 0; i < array.length; i ++){ for(var j = 0; j< array.length; j++){ if(i =! j) { array[j]; }}}
is what i was talking about
Riful
@timburrows
Apr 03 2016 09:38
i+1 will equal to the next index in the interator
it's the same as accessing the array directly, array[0], array[1] etc
Dave Melia
@Dave-Melia
Apr 03 2016 09:38
@RifuI okay cool. I'll have a play, thanks
CamperBot
@camperbot
Apr 03 2016 09:38
dave-melia sends brownie points to @rifui :sparkles: :thumbsup: :sparkles:
Riful
@timburrows
Apr 03 2016 09:38
instead, to access the next element, your essentially doing array[0+1]