These are chat archives for FreeCodeCamp/HelpJavaScript

7th
Nov 2016
Aiden
@AidenMead
Nov 07 2016 00:01 UTC
Hey everyone!
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:01 UTC
hey
Tony Miri
@TonyMiri
Nov 07 2016 00:01 UTC
Does anyone have an idea about why this code for a search box isn't working?
document.ready(function() {

  $('#input').keyup(function() {

    var searchText = this.val();

    $('#streamer').each(function() {
      if ($(this).text().search(new RegExp(searchText, "i")) < 0) {
          $(this).fadeOut();
      } else {
          $(this).show();
      }//if-else
    });//#streamer.each    
  });//#input.keyup
});//document.ready
Joseph
@revisualize
Nov 07 2016 00:02 UTC
Hello.
Aiden
@AidenMead
Nov 07 2016 00:02 UTC
I'm having some trouble (and by that I mean I've been completely stuck for nearly two months) with the random quote machine, anyone willing to look at it and see if they can figure out what's going on? From all of my research, my js should be working, but apparently something isn't quite right.
Joseph
@revisualize
Nov 07 2016 00:03 UTC
@AidenMead Are you using Codepen? And are you tying to access an API that is via an HTTP call?
Tony Miri
@TonyMiri
Nov 07 2016 00:04 UTC
CORS
Joseph
@revisualize
Nov 07 2016 00:05 UTC
@AidenMead Yup!
@AidenMead Codepen and Chrome do not allow what you're doing.
Aiden
@AidenMead
Nov 07 2016 00:05 UTC
I'm still struggling with identifying the different types of APIs, lol.
Joseph
@revisualize
Nov 07 2016 00:06 UTC
@AidenMead You can't have an HTTP API.
Aiden
@AidenMead
Nov 07 2016 00:06 UTC
Ohhhhhh, so it's not my code, it's just codepen, eh?
Ah, hmm, okay.
Joseph
@revisualize
Nov 07 2016 00:06 UTC
@AidenMead Try using https://crossorigin.me/ to pass your api call through.
@AidenMead Well, it could still be your code.
Aiden
@AidenMead
Nov 07 2016 00:07 UTC
lol, I'll give that a shot, thank you, @revisualize
CamperBot
@camperbot
Nov 07 2016 00:07 UTC
aidenmead sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 2257 | @revisualize |http://www.freecodecamp.com/revisualize
c0d0er
@c0d0er
Nov 07 2016 00:07 UTC
@walidashri thanks
CamperBot
@camperbot
Nov 07 2016 00:07 UTC
c0d0er sends brownie points to @walidashri :sparkles: :thumbsup: :sparkles:
:cookie: 589 | @walidashri |http://www.freecodecamp.com/walidashri
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:08 UTC
can anyone help me with my problem?
Iqbal
@mibaldobaghi
Nov 07 2016 00:08 UTC
@muzzotech i got it done
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:08 UTC
@mibaldobaghi how?
AsmodeusMictian
@AsmodeusMictian
Nov 07 2016 00:08 UTC
Can someone confirm that I'm not crazy?
If I have the following if statement, and I put the number 25 in, it should return TRUE....right?
if (val <= 50 && val >= 25)
Iqbal
@mibaldobaghi
Nov 07 2016 00:08 UTC
i created a new object instead of changing the object
i not sure why but that passed it
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:09 UTC
awesome
Tony Miri
@TonyMiri
Nov 07 2016 00:09 UTC
@AidenMead First thing you're going to want to do is load the jquery library
Iqbal
@mibaldobaghi
Nov 07 2016 00:09 UTC
```
function orbitalPeriod(arr) {
  var GM = 398600.4418;
  var earthRadius = 6367.4447;
  var orbPeriod;
  var answer = [];

  for(i = 0; i < arr.length;i++){
    var radius = earthRadius + arr[i].avgAlt;
    orbPeriod = Math.round( 2 * Math.PI *(Math.sqrt(Math.pow(radius,3)/GM)));
    var satellite = {
      name: arr[i].name,
      orbitalPeriod: orbPeriod

    };
    answer.push(satellite);
  }
  return answer;
}

orbitalPeriod([{name: "iss", avgAlt: 413.6}, {name: "hubble", avgAlt: 556.7}, {name: "moon", avgAlt: 378632.553}]);
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:09 UTC
function findElement(arr, func) {
  var num = 0;
  for(var n = 0; n < arr.length; n++){
    func(arr[n]);
    if(func){
      num = arr[n];
    }
  }
  return num;
}

findElement([1, 3, 5, 8, 9], function(num){ return num % 2 === 0; });
Iqbal
@mibaldobaghi
Nov 07 2016 00:09 UTC
the result was the same though
i doing the exact change challenge
what does penny,1.01 mean? 101 pennies?
Aiden
@AidenMead
Nov 07 2016 00:11 UTC
@FatTone225 Oh man, how did I overlook that?
That seems to allow the request to pull, now
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:11 UTC
I'm not sure seeing as it would be 1.01 dollars to equal 101 pennies
Tony Miri
@TonyMiri
Nov 07 2016 00:12 UTC
@AidenMead Yeah. lol. It's always the simple things that cause the biggest holdups
Aiden
@AidenMead
Nov 07 2016 00:12 UTC
@FatTone225 thanks for catching that!
CamperBot
@camperbot
Nov 07 2016 00:12 UTC
aidenmead sends brownie points to @fattone225 :sparkles: :thumbsup: :sparkles:
:cookie: 383 | @fattone225 |http://www.freecodecamp.com/fattone225
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:12 UTC
@mibaldobaghi yes, it is what it means
pennies, $1.01
Aiden
@AidenMead
Nov 07 2016 00:13 UTC
Now I'll just have to catch my head a bit about how to get it to pull a different quote each time I hit the button, it seems to only pull one.
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:14 UTC
Tony Miri
@TonyMiri
Nov 07 2016 00:14 UTC
@AidenMead Yeah not sure about that. Probably best to check back with their documentation.
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:15 UTC
Can anyone help me with my problem?
Iqbal
@mibaldobaghi
Nov 07 2016 00:16 UTC
@muzzotech i can try
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:16 UTC
thanks
Iqbal
@mibaldobaghi
Nov 07 2016 00:16 UTC
@AidenMead are u using variables to store the quote?
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:17 UTC
it just returns the last number in the array as opposed to the correct variable
when I put in a break statement, it gives me the first number
Mel DeJesus
@edgewood1
Nov 07 2016 00:17 UTC
Has anyone finished the "stand in line" exercise? My problem is that the code below doesn't satisfy this: nextInLine([5,6,7,8,9], 1) should return 5. The code: function nextInLine(arr, item) {
testArr.push(item);
b=testArr.shift();
return b;
}
// 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));
Tony Miri
@TonyMiri
Nov 07 2016 00:17 UTC
@AidenMead Look into clearing the cache for your ajax call
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:18 UTC
@edgewood1 you need to replace the testArr statements with arr
Aiden
@AidenMead
Nov 07 2016 00:18 UTC
@mibaldobaghi I hadn't in my latest version, but in a previous i tried to, it just wasn't working so I scrapped it. I can try again.
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:18 UTC
testArr only exists outside of the function
Iqbal
@mibaldobaghi
Nov 07 2016 00:19 UTC
@muzzotech which challenge are u doing?
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:19 UTC
Finders Keepers
Tony Miri
@TonyMiri
Nov 07 2016 00:19 UTC
@muzzotech Sometimes it helps to troubleshoot if you write comments of pseudocode next to each line
Chris Rutherford
@cjrutherford
Nov 07 2016 00:23 UTC
have a quick question. Why does this code not modify the innerHTML? I'm not sure why this isn't working.....
 function compTurn() {
    for (var j = 0; j < winCon.length; j++) {
      if ((winCon[j][0] in selected) && (winCon[j][1] in selected)) {
        console.log("The first if is the one!");
      } else if ((winCon[j][0] in selected) && (winCon[j][2] in selected)) {
        console.log("The Second One");
      } else if ((winCon[j][1] in selected) && (winCon[j][2] in selected)) {
        console.log("the third one.");
      } else {
        console.log("No Blocks");
      }
    }

    console.log('playing a random...');
    var maxi = board.length;
    var index = Math.floor(Math.random() * (maxi - 0));
    console.log(index);
    var board = $('.board').toArray();
    board[index].innerHTML = '<h2 class="token">' + comptoken + '</h2>';
  }
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:25 UTC
@cjrutherford Where does the comptoken come in? I don't see that variable at all
Chris Rutherford
@cjrutherford
Nov 07 2016 00:25 UTC
@muzzotech it's defined earlier when the player selects their token (X/Y)
it's global
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:26 UTC
okay then shouldn't it read $(board[index]).innerHTML...
Chris Rutherford
@cjrutherford
Nov 07 2016 00:27 UTC
wait it's supposed to be O, and I figured it out. there was a second array called board defined.... and yes, but I did it a slightly different way.
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:28 UTC
ok
this is the full pen
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:29 UTC
@mibaldobaghi Any news?
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:40 UTC

Based on notes from @FatTone225 this is my code:

function findElement(arr, func) {
  var num = 0;
  for(var n = 0; n < arr.length; n++){
//     run the function
    func(arr[n]);
//     if the function returns true, return that number
    if(func){
      num = arr[n];
    }
  }
  return num;
}

findElement([1, 3, 5, 8, 9], function(num){ return num % 2 === 0; });

It's for Finders Keepers. What it should return is 8 but it returns 9.

Aiden
@AidenMead
Nov 07 2016 00:40 UTC
Hmmm, so I switched over the a .ajax request instead of a .getJSON, so that I could incorporate the cache:false option, but it still won't pull a new quote on each button click.
haha, bizarre, it won't work in the preview, but it works when I'm actually on the codepen site
He Liu
@HeLiu
Nov 07 2016 00:46 UTC
hey guys if you do typeof [1,2,3,4]
it should return back as an array
right?
Mel DeJesus
@edgewood1
Nov 07 2016 00:46 UTC
@revisualize Thanks for the link - my code satisfies all the returns except for the third one (return 5).
CamperBot
@camperbot
Nov 07 2016 00:46 UTC
edgewood1 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 2260 | @revisualize |http://www.freecodecamp.com/revisualize
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:46 UTC
@HeLiu I think it should return an object
arrays are within {}
He Liu
@HeLiu
Nov 07 2016 00:46 UTC
thats what im confused about @muzzotech
it says it should be returned as an object
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:47 UTC
but it's coming up as an array?
He Liu
@HeLiu
Nov 07 2016 00:47 UTC
so it returns back as an object?
so arrays are within objects
no its coming up as an object lol
im on a page teaching typeof operator
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:48 UTC
yeah, anything within [] is an object
He Liu
@HeLiu
Nov 07 2016 00:48 UTC
im just on here getting confirmation
@muzzotech ok thanks
CamperBot
@camperbot
Nov 07 2016 00:48 UTC
heliu sends brownie points to @muzzotech :sparkles: :thumbsup: :sparkles:
:cookie: 7 | @muzzotech |http://www.freecodecamp.com/muzzotech
Nicola Scaramuzzo
@muzzotech
Nov 07 2016 00:48 UTC
no worries
Tony Miri
@TonyMiri
Nov 07 2016 00:49 UTC
@AidenMead So, after your ajax call, inside your callback function, add a console.log(a) and see what you're getting
Aiden
@AidenMead
Nov 07 2016 00:52 UTC
@FatTone225 when I do that, whether I add the console.log or replace my function result, it doesn't actually print anything in there
Tony Miri
@TonyMiri
Nov 07 2016 00:54 UTC
Here is what I mean:
       url: "http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1",
       success: function(a){
           $(".quote").replaceWith(a[0].content + "<p>-" + a[0].title + "</p>");
         console.log(a);
         }
Aiden
@AidenMead
Nov 07 2016 00:54 UTC
However, if I .append instead of .replaceWith, I do get new quotes, they just stack, so I'll have to work to find a way to store and replace them
Chris Rutherford
@cjrutherford
Nov 07 2016 00:58 UTC
hey all, looking for some advice on code on this one....
Tony Miri
@TonyMiri
Nov 07 2016 01:00 UTC
@AidenMead Right. You are receiving the correct information, but I don't think you have your code to replace the code quite right. What you were saying is that you want to replace the <p> with the class 'quote' with the response text. But when you replaced it, you didn't give your new paragraph the class 'quote' so the new one's weren't getting replaced.
Mel DeJesus
@edgewood1
Nov 07 2016 01:03 UTC
@muzzotech double thanks! is this because the function's code block should only work on the parameters, rather than other variable in the display code? I do see how the 2nd console.log line assigns testArr to arr, so regardless, it makes sense to deal with arr instead...
CamperBot
@camperbot
Nov 07 2016 01:03 UTC
:cookie: 8 | @muzzotech |http://www.freecodecamp.com/muzzotech
edgewood1 sends brownie points to @muzzotech :sparkles: :thumbsup: :sparkles:
Aiden
@AidenMead
Nov 07 2016 01:05 UTC
@FatTone225 Hmmm, i gave that a shot, but it still just gives me the first quote and won't refresh with a new one.
Tony Miri
@TonyMiri
Nov 07 2016 01:05 UTC
@AidenMead Yeah I couldn't seem to get it either. hmmmm
Aiden
@AidenMead
Nov 07 2016 01:08 UTC
So I've gotten it to a point where it will continue to send a new quote, but it places it directly below the old one instead of in it's place. I tried to add a remove option before the .append, but that doesn't work.
Chris Rutherford
@cjrutherford
Nov 07 2016 01:09 UTC
@AidenMead try setting the innerHtml property of your quote tag to the empty string
$('#thisID').innerHtml = '';
Aiden
@AidenMead
Nov 07 2016 01:11 UTC
That didn't seem to do anything, either
Chris Rutherford
@cjrutherford
Nov 07 2016 01:12 UTC
care to share you pen?
Chris Rutherford
@cjrutherford
Nov 07 2016 01:16 UTC
what I see is :
$(".quote").replaceWith(a[0].quoteText + "<p>-" + a[0].quoteAuthor + "</p>");
which replaces the entire tag, and I'm not sure you want to do that
Garrus Napp
@GarrusNapp
Nov 07 2016 01:17 UTC
@AidenMead maybe .html would work better
Aiden
@AidenMead
Nov 07 2016 01:19 UTC
Got ittttt
Chris Rutherford
@cjrutherford
Nov 07 2016 01:19 UTC
I would probably work with this line like this: `$('.quote').innerHtml = data.quoteText + "<p>-" + data.quoteAuthor +"</p>";
Solomon B
@ssbothwell
Nov 07 2016 01:19 UTC
Hi guys, I'm having some trouble with the Smallest Common Multiple exercise. I have a working solution but it requires generating a list of multiples for all numbers in the target range. this is fine for smaller ranges, but if the range is too big then the multiples list gets huge and crashes the browser.
Aiden
@AidenMead
Nov 07 2016 01:19 UTC
I ended up using the empty manipulator to clear the tag before appending the new quote
Solomon B
@ssbothwell
Nov 07 2016 01:20 UTC
im sure theres a more efficient solution. can anyone look at my code and give me some suggestions?
Tony Miri
@TonyMiri
Nov 07 2016 01:20 UTC
@AidenMead Glad you got it! I have no idea why that wouldn't work
Chris Rutherford
@cjrutherford
Nov 07 2016 01:20 UTC
@AidenMead kudos glad you found a solution!
pavisri
@pavisri
Nov 07 2016 01:20 UTC
Hey everyone
sandlasd
@sandlasd
Nov 07 2016 01:20 UTC
hey
Solomon B
@ssbothwell
Nov 07 2016 01:21 UTC
and whats the best way to paste code in here without being spammy?
pavisri
@pavisri
Nov 07 2016 01:21 UTC
I’m working on Diff Two Arrays challenge
Aiden
@AidenMead
Nov 07 2016 01:21 UTC
@cjrutherford do you have any resources or article on "innerHTML"? I'm not familiar with it at all, but would definitely like to read up on it.
pavisri
@pavisri
Nov 07 2016 01:21 UTC
Here is what i have:
Chris Rutherford
@cjrutherford
Nov 07 2016 01:21 UTC
@AidenMead of course! here you go! http://www.w3schools.com/jsref/prop_html_innerhtml.asp
Aiden
@AidenMead
Nov 07 2016 01:22 UTC
thank you @FatTone225 and @cjrutherford . I've been stuck on that for so long, but having you guys walk through some options really helped get the gears grinding on how to structure things to find a solution.
CamperBot
@camperbot
Nov 07 2016 01:22 UTC
aidenmead sends brownie points to @fattone225 and @cjrutherford :sparkles: :thumbsup: :sparkles:
:cookie: 384 | @fattone225 |http://www.freecodecamp.com/fattone225
:cookie: 303 | @cjrutherford |http://www.freecodecamp.com/cjrutherford
pavisri
@pavisri
Nov 07 2016 01:22 UTC
What am i missing? It works fine but for rrays with same length it doesn’t.
Solomon B
@ssbothwell
Nov 07 2016 01:22 UTC
heres my kinda working solution for Smallest Common Multiple: http://dpaste.com/3Q5DR58
any suggestions?
pavisri
@pavisri
Nov 07 2016 01:22 UTC

function diffArray(arr1, arr2) {
var bigArr = [];
var smallArr = [];
if(arr1.length > arr2.length) {
bigArr = arr1;
smallArr = arr2;
}else if (arr2.length > arr1.length) {
bigArr = arr2;
smallArr = arr1;
}

function filterByNum (val) {
return smallArr.indexOf(val) === -1;
}
var result = bigArr.filter(filterByNum);
return result;
}

diffArray(["andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"]);

Aiden
@AidenMead
Nov 07 2016 01:23 UTC
get the gears spinning* haha, wouldn't want them to grind, but I guess that's why i learning to code instead of learning mechanics
Tony Miri
@TonyMiri
Nov 07 2016 01:23 UTC
@AidenMead No problem. Funny thing is I've done that one already and I still couldn't figure it out again. I remember having to struggle with it for a long time too. I think I ended up taking a different route, but yours is more elegant.
pavisri
@pavisri
Nov 07 2016 01:24 UTC
Screen Shot 2016-11-06 at 7.20.08 PM.png
Screen Shot 2016-11-06 at 7.20.08 PM.png
Screen Shot 2016-11-06 at 7.20.08 PM.png
Bobby
@heebzstreet
Nov 07 2016 01:28 UTC
anybody got the nesting for loops exercise down?
Ryan Uselmann
@SiriusScaper
Nov 07 2016 01:37 UTC
I could use some help understanding why map isn’t quite working with chunky monkey.
Joseph
@revisualize
Nov 07 2016 01:38 UTC
@heebzstreet I do.
Ryan Uselmann
@SiriusScaper
Nov 07 2016 01:38 UTC
let chunkArrayInGroups = (arr, size) => { return arr.map(() => arr.splice(0, size)).filter((x) => (x !== (undefined))); };
Joseph
@revisualize
Nov 07 2016 01:39 UTC
because you don't have a parameter.
Jenky W. Nolasco
@jenkynolasco11
Nov 07 2016 01:40 UTC
@SiriusScaper you ain't passing a parameter in the arrow function
Joseph
@revisualize
Nov 07 2016 01:41 UTC
You aren't passing to a parameter.
You pass an argument. You pass to a parameter.
Ryan Uselmann
@SiriusScaper
Nov 07 2016 01:41 UTC
Sorry I should clarify. It passes some of the tests, but ones like chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3); return [[0,1,2],[3,4,5]]
And doesn’t return 6
Joseph
@revisualize
Nov 07 2016 01:42 UTC
@SiriusScaper have you tried using www.pythontutor.com/javascript.html to visualize your code execution?
Ryan Uselmann
@SiriusScaper
Nov 07 2016 01:42 UTC
Yep
Joseph
@revisualize
Nov 07 2016 01:42 UTC
Well, What is failing?
KiritoKyun
@KiritoKyun
Nov 07 2016 01:42 UTC
function nextInLine(arr, item) {
  // Your code here
  arr.push(item);
  arr.shift();
  return ;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
I'm confused as to how to return the value that was removed from the array
Joseph
@revisualize
Nov 07 2016 01:42 UTC
@KiritoKyun You need to return the element that was removed.
@KiritoKyun What does .shift() return?
He Liu
@HeLiu
Nov 07 2016 01:43 UTC

hey guys i have a question about these instructions

Write a function removeOddValues that takes an object as an argument and returns an object with all key/value pairs removed for which the value holds an odd number. You'll need to use the typeof operator to first check that the values are numbers.

KiritoKyun
@KiritoKyun
Nov 07 2016 01:43 UTC
.shift() doesn't return anything, I'm supposed to push the item to the end of the array and remove the first element of the array @revisualize
Joseph
@revisualize
Nov 07 2016 01:44 UTC
@KiritoKyun Incorrect.
Jenky W. Nolasco
@jenkynolasco11
Nov 07 2016 01:44 UTC
Compare if the type of argument in the array is a number @HeLiu
Joseph
@revisualize
Nov 07 2016 01:44 UTC
@KiritoKyun It does return something.
He Liu
@HeLiu
Nov 07 2016 01:44 UTC
i was doing typeof [key] === 'number' && [key] %2===0
KiritoKyun
@KiritoKyun
Nov 07 2016 01:44 UTC
Oh thanks @revisualize
CamperBot
@camperbot
Nov 07 2016 01:44 UTC
kiritokyun sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 2261 | @revisualize |http://www.freecodecamp.com/revisualize
He Liu
@HeLiu
Nov 07 2016 01:44 UTC
but then i realize well if its divisible by 2 then its obv a number
then why do i need to use the type of operator
kingsleychino
@kingsleychino
Nov 07 2016 01:44 UTC
hello please I need some help
Jenky W. Nolasco
@jenkynolasco11
Nov 07 2016 01:45 UTC
because you could get strings in the array
Joseph
@revisualize
Nov 07 2016 01:45 UTC

"Talk is cheap. Show me the code." - Linus Torvalds (2000-08-25).

He Liu
@HeLiu
Nov 07 2016 01:45 UTC
maybe im just overthinking...it has been a long day
am i on the right track with my setup tho
Joseph
@revisualize
Nov 07 2016 01:46 UTC
Couldn't tell you.
Ryan Uselmann
@SiriusScaper
Nov 07 2016 01:47 UTC
@revisualize Nothing is failing. It’s just not returning all the elements and I’m not sure why or how to fix it
Joseph
@revisualize
Nov 07 2016 01:47 UTC
@SiriusScaper I need to know what tests aren't working.
I need to be able to run your code to see what isn't working.
Help me run your code.
CamperBot
@camperbot
Nov 07 2016 01:47 UTC
no wiki entry for: me run your code
Joseph
@revisualize
Nov 07 2016 01:47 UTC
Please?
Ryan Uselmann
@SiriusScaper
Nov 07 2016 01:48 UTC
ok
He Liu
@HeLiu
Nov 07 2016 01:48 UTC
@jenkynolasco11 but hey if its divisible by 2 then its obviously not a string
Ryan Uselmann
@SiriusScaper
Nov 07 2016 01:48 UTC
@revisualize
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2) should return [[0, 1], [2, 3], [4, 5]].
chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3) should return [[0, 1, 2], [3, 4, 5], [6]].
chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4) should return [[0, 1, 2, 3], [4, 5, 6, 7], [8]].
chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2) should return [[0, 1], [2, 3], [4, 5], [6, 7], [8]].
Mikel
@kel-amg
Nov 07 2016 01:50 UTC
```function lookUpProfile(firstName, prop){
// Only change code below this line
for (var x = 0; x < contacts.length; x++){
if (contacts[x].firstName === firstName && contacts[x].hasOwnProperty(prop)) {
return contacts[x][prop];
} else {
return "No such property";
}
}
return "No such contact";
// Only change code above this line
}
Need help with this
What is wrong with the code?
kingsleychino
@kingsleychino
Nov 07 2016 01:55 UTC
please guys I need a hand in this code
@revisualize please help me
Joseph
@revisualize
Nov 07 2016 02:01 UTC
I'm on the :toilet:
Afk?
He Liu
@HeLiu
Nov 07 2016 02:04 UTC
Write a function removeOddValues that takes an object as an argument and returns an object with all key/value pairs removed for which the value holds an odd number. You'll need to use the typeof operator to first check that the values are numbers:
function removeOddValues(obj){
  var newObj = {};
  for(var key in obj){
    if(typeof key === 'number' && key % 2 === 0){
       newObj[key] = obj[key];
    }
  }return newObj;
}

removeOddValues(liuHe = {a: 2, b: 'liu', c: 4, d: 5, e: 7});
this was my code and test for the problem....it just returns an empty object...
Joseph
@revisualize
Nov 07 2016 02:09 UTC
Objects are key value pairs.
@SiriusScaper You're silly. I'm not just going to run every single one of those tests and just magically try to figure out what isn't working.
He Liu
@HeLiu
Nov 07 2016 02:13 UTC
im sorry but...i really dont get what youre trying to hint at here @revisualize
are you saying typeof key === number is wrong
Ryan Uselmann
@SiriusScaper
Nov 07 2016 02:14 UTC
@revisualize Sorry. I haven’t really asked for help before. Those are cases that do not work. I meant to send the ones that do, one sec.
chunkArrayInGroups(["a", "b", "c", "d"], 2) should return [["a", "b"], ["c", "d"]].
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3) should return [[0, 1, 2], [3, 4, 5]].
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4) should return [[0, 1, 2, 3], [4, 5]].
Joseph
@revisualize
Nov 07 2016 02:15 UTC
@kel-amg Your for loop is ALWAYS returning something. Therefore the function will terminate early.
Ryan Uselmann
@SiriusScaper
Nov 07 2016 02:15 UTC
those work
Joseph
@revisualize
Nov 07 2016 02:16 UTC
@kingsleychino I've scrolled up through the last hour. I don't see a question.
Tony Miri
@TonyMiri
Nov 07 2016 02:16 UTC
Hey is twitch.tv working for anyone right now?
I can't even load the homepage
Joseph
@revisualize
Nov 07 2016 02:16 UTC
Those work or those don't work?
Walid Ashri
@walidashri
Nov 07 2016 02:17 UTC
@FatTone225 working here
Solomon B
@ssbothwell
Nov 07 2016 02:17 UTC
@FatTone225 working here
Tony Miri
@TonyMiri
Nov 07 2016 02:17 UTC
wtf
Oh there it goes
Joseph
@revisualize
Nov 07 2016 02:19 UTC
@SiriusScaper Looks like your function works. I have no idea.
@SiriusScaper Well, this test doesn't work: chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3);
Baraka Mahili
@gbmahili
Nov 07 2016 02:20 UTC
Just finished this Twitch challenge...can you guys provide feedback? Am ready to move on to the next challenge....Here is my pen: http://codepen.io/GBMahili/full/ORKRMr/
Thanks
Ryan Uselmann
@SiriusScaper
Nov 07 2016 02:21 UTC
@revisualize Yeah, all the others do not work.
Joseph
@revisualize
Nov 07 2016 02:21 UTC
@HeLiu No.. Objects are key value pairs.
@SiriusScaper I have no idea. I think your code is too advanced for FCC.
I just did it the lazy way.
Ryan Uselmann
@SiriusScaper
Nov 07 2016 02:22 UTC
@revisualize apparently too advanced for me also :P
Tony Miri
@TonyMiri
Nov 07 2016 02:22 UTC
Could someone do me a favor? I'm almost done with this, but when I click on a user to try to view them on twitch.tv I am getting just a blank page. Is it working for anyone else? http://codepen.io/TonyMiri/pen/yamwVR
Joseph
@revisualize
Nov 07 2016 02:22 UTC
@HeLiu
/collapse-all
blob
Tony Miri
@TonyMiri
Nov 07 2016 02:24 UTC
@gbmahili Looks good! Maybe it's just my computer or something, but I'm not able to load any actual streams from your app either.
Christopher Lavine
@Christopher37
Nov 07 2016 02:24 UTC
Can someone please help me and see what am i doing wrong

var count = 0;

function cc(card) {
// Only change code below this line
var answer = "";
if (card <= 6){
count+= 1;
if (count > 0){
answer = "Bet";
}

else {
answer = "Hold";
}
return count + answer;
}

else if(card > 6 && card > 10){
if (count > 0);
answer = "Bet";
}
else{
answer = "Hold";
}
return count + answer;
}
else {
count-=1;
if(count > 0) {
answer = "Bet";
}
else {
answer = "Hold";
}

// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

He Liu
@HeLiu
Nov 07 2016 02:24 UTC
@revisualize ohhhhh ok
thank you!!
i keep forgetting ro use pythontutor lol
to*
Christopher Lavine
@Christopher37
Nov 07 2016 02:27 UTC
Anyone PLEASE!!!
He Liu
@HeLiu
Nov 07 2016 02:28 UTC
please of all
use tick marks
Amit Patel
@AmitP88
Nov 07 2016 02:28 UTC
hey guys, I have a question that's unrelated to web dev. I'm trying to decide on whether I should get my dad the iphone7 or the Google Pixel XL. The thing is, I think my dad slightly prefers apple products because he likes to facetime with my uncle in England (we're in the US), but he already has an ipad air 2 for that. I've heard a lot of complaints about the new iphone and I really want to make sure my dad has a good phone. I also don't want to ask him because I want it to be a surprise for this christamas. what should I do?
He Liu
@HeLiu
Nov 07 2016 02:29 UTC
first*
Amit Patel
@AmitP88
Nov 07 2016 02:29 UTC
the other thing is both my dad and I haven't really had any decent phones in the past (mostly cheapo phones - even our smartphones are cheap)
Christopher Lavine
@Christopher37
Nov 07 2016 02:34 UTC
@HeLiu dont respond back to me unless you're trying to help thanks
CamperBot
@camperbot
Nov 07 2016 02:34 UTC
christopher37 sends brownie points to @heliu :sparkles: :thumbsup: :sparkles:
:cookie: 6 | @heliu |http://www.freecodecamp.com/heliu
kingsleychino
@kingsleychino
Nov 07 2016 02:35 UTC
@revisualize please I have been busy trying to solve the problem by self but, I cant. Please I really need your help okay

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

switch (val === "bob") {
answer = "Marley";
case 42:
answer = "The Answer";
break;
case 1:
answer = "There is no #1";
break;
case 99:
answer = "Missed me by this much!";
break;
case 7:
answer = "Ate Nine";
}

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

// Change this value to test
chainToSwitch(7);

@camperbot please the this code for me
Jeff Shapiro
@Jeff-Shapiro
Nov 07 2016 02:50 UTC
@kingsleychino your issue lies around thie part answer = "Marley";
Diego Mayer
@Chrono79
Nov 07 2016 02:52 UTC
@kingsleychino this isn't right: switch (val === "bob") { look at the example code to see how a switch block is build
kingsleychino
@kingsleychino
Nov 07 2016 02:53 UTC
@Jeff-Shapiro how
@Chrono79 please show me the code
He Liu
@HeLiu
Nov 07 2016 02:56 UTC
@Christopher37 i am trying to help. use tick marks so your code can be more readable and in the proper format
Jeff Shapiro
@Jeff-Shapiro
Nov 07 2016 02:56 UTC
@kingsleychino sorry I don't give solutions
Diego Mayer
@Chrono79
Nov 07 2016 02:56 UTC
switch (val) {
  case 1:
    answer = "a";
    break;
  case 2:
    answer = "b";
    break;
  default:
    answer = "c";
}
I meant this one @kingsleychino
Compare it with what you wrote
Diego Mayer
@Chrono79
Nov 07 2016 03:05 UTC
@Christopher37 you have 2 errors in your code
card > 6 && card > 10 this condition
and what you return, it'll look like 5Bet instead of 5 Bet
Solomon B
@ssbothwell
Nov 07 2016 03:06 UTC
i think i'm experiencing a bug.
with an if statement inside a for loop
its really weird
if i paste a bunch of copies of the if statement without a loop it behaves correctly
Diego Mayer
@Chrono79
Nov 07 2016 03:07 UTC
@ssbothwell show your code
its returning [5,6,7] instead of [6,7]
but if i copy/paste a bunch of those if statements to manually simulate looping over it, i get the correct [6,7]
Diego Mayer
@Chrono79
Nov 07 2016 03:09 UTC
@ssbothwell try returning outside the loop and using break
Solomon B
@ssbothwell
Nov 07 2016 03:09 UTC
im not even using the second conditional
its commented out
im using the return outside the loop to check the value

this if statement doesn't seem to work right when inside the loop:
if ( func(arr[0] ) === false) {
arr = arr.slice(1);
}

it passes on a value of 5

when the func is checking > 5
am i missing something?
Diego Mayer
@Chrono79
Nov 07 2016 03:16 UTC
@ssbothwell there is a problem when you change the array length while looping
Solomon B
@ssbothwell
Nov 07 2016 03:17 UTC
oooh, that makes sense
i hadnt really considered how that would change the loop conditions
Diego Mayer
@Chrono79
Nov 07 2016 03:18 UTC
@ssbothwell you could store the original lenght in a var or use a while loop
Solomon B
@ssbothwell
Nov 07 2016 03:18 UTC
yeah that makes sense
@Chrono79 thanks!
CamperBot
@camperbot
Nov 07 2016 03:18 UTC
ssbothwell sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 2439 | @chrono79 |http://www.freecodecamp.com/chrono79
zjhjszwx
@zjhjszwx
Nov 07 2016 03:37 UTC
How to convert the string "+" to the + operator
Jenky W. Nolasco
@jenkynolasco11
Nov 07 2016 03:43 UTC
you can use eval()... but better do an if statement
eval is a bad practice
zjhjszwx
@zjhjszwx
Nov 07 2016 03:47 UTC
@jenkynolasco11 thank you
CamperBot
@camperbot
Nov 07 2016 03:47 UTC
zjhjszwx sends brownie points to @jenkynolasco11 :sparkles: :thumbsup: :sparkles:
:cookie: 371 | @jenkynolasco11 |http://www.freecodecamp.com/jenkynolasco11
AbbyLOL
@AbbyLOL
Nov 07 2016 04:08 UTC
ANYBODY HELP!!!!!
I am stuck

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

// Only change code below this line;

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

Abhishek Kumar
@Mr-Kumar-Abhishek
Nov 07 2016 04:13 UTC
@AbbyLOL playerNumber should be just the number what you are looking for
AbbyLOL
@AbbyLOL
Nov 07 2016 04:13 UTC
oh ok
Abhishek Kumar
@Mr-Kumar-Abhishek
Nov 07 2016 04:13 UTC
@AbbyLOL such as 12 or 16
AbbyLOL
@AbbyLOL
Nov 07 2016 04:13 UTC
what about player
Abhishek Kumar
@Mr-Kumar-Abhishek
Nov 07 2016 04:14 UTC
@AbbyLOL and then use that number stored in that var to access the object
AbbyLOL
@AbbyLOL
Nov 07 2016 04:15 UTC
oh ok thanks @Mr-Kumar-Abhishek
CamperBot
@camperbot
Nov 07 2016 04:15 UTC
abbylol sends brownie points to @mr-kumar-abhishek :sparkles: :thumbsup: :sparkles:
:cookie: 390 | @mr-kumar-abhishek |http://www.freecodecamp.com/mr-kumar-abhishek
can anybody help me with this??
HELP
I son't really understand
HELp anybody
CamperBot
@camperbot
Nov 07 2016 04:27 UTC
no wiki entry for: anybody
Jenky W. Nolasco
@jenkynolasco11
Nov 07 2016 04:28 UTC
@
@AbbyLOL instead of switch(val), make it an object
And assign result to that lookup value
AbbyLOL
@AbbyLOL
Nov 07 2016 04:32 UTC
val phoneticLookup = {
"alpha":"Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank"
};
Like this?
though it still doesn't work
Jenky W. Nolasco
@jenkynolasco11
Nov 07 2016 04:34 UTC
Yeah, like that
But still, you gotta look it up using the bracket or dot notation, assign that value to return
AbbyLOL
@AbbyLOL
Nov 07 2016 04:35 UTC
i don't really get it
Jenky W. Nolasco
@jenkynolasco11
Nov 07 2016 04:35 UTC
So, you have this:
var obj = {
  1 : 'something',
  2 : 'like',
  3 : 'this'
}
you can get any value from there like this:
var str =  obj[1] // str has 'something'
That's bracket notation
You access the value via a bracket, using a key, which in this case, are 1, 2, and 3

You could also have this:

var key = 1
var str = obj[key] // str has 'something'

which is also the same

In case the object were like this:
var obj = {
 'key1' : 'something',
 'key 2' : 'like',
  key3 : 'this'
}
you could access each value via either bracket or dot notation
example:
AbbyLOL
@AbbyLOL
Nov 07 2016 04:40 UTC
then what's wrong with my code
Jenky W. Nolasco
@jenkynolasco11
Nov 07 2016 04:41 UTC
you have this:
switch(val) {
    "alpha":"Adams",
    "bravo":"Boston",
    "charlie":"Chicago",
    "delta":"Denver",
    "echo":"Easy"
    "foxtrot":"Frank"
  }
It's asking you to change it to an object, assign the result variable to the string given the val key, and return result
AbbyLOL
@AbbyLOL
Nov 07 2016 04:43 UTC
var phoneticLookup = {
"alpha" : "Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank"
};
like this?
Jenky W. Nolasco
@jenkynolasco11
Nov 07 2016 04:43 UTC
Yes
silver537
@silver537
Nov 07 2016 04:43 UTC
that's half of it'
Jenky W. Nolasco
@jenkynolasco11
Nov 07 2016 04:44 UTC
^
AbbyLOL
@AbbyLOL
Nov 07 2016 04:44 UTC
then how should I further change it
silver537
@silver537
Nov 07 2016 04:44 UTC
the other half: assign the result variable to the string given the val key, and return result
Jenky W. Nolasco
@jenkynolasco11
Nov 07 2016 04:44 UTC
^^^
AbbyLOL
@AbbyLOL
Nov 07 2016 04:46 UTC
var phoneticLookup = {
"alpha" : "Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank"
};
var phoneticLookup = ""
var str = phoneticLookup[undefined]
like this?
Jenky W. Nolasco
@jenkynolasco11
Nov 07 2016 04:47 UTC
Uhm don't do the var phoneticLookup = ''
You already declared it as an object
silver537
@silver537
Nov 07 2016 04:48 UTC
daaaaamn. did you read at all what ^ this guy said?
AbbyLOL
@AbbyLOL
Nov 07 2016 04:48 UTC
i did...
silver537
@silver537
Nov 07 2016 04:49 UTC
:point_up: November 6, 2016 10:35 PM
@AbbyLOL read carefully. he literally gives you the answer.
AbbyLOL
@AbbyLOL
Nov 07 2016 04:50 UTC
ok
Jenky W. Nolasco
@jenkynolasco11
Nov 07 2016 04:52 UTC
@AbbyLOL tip: you already are given with the key
javescript
@javescript
Nov 07 2016 05:17 UTC
can someone help me with document.write()
Jenky W. Nolasco
@jenkynolasco11
Nov 07 2016 05:19 UTC
What up with that?
Jace
@jacebenson
Nov 07 2016 05:22 UTC
@javescript what do you mean, whats the issue?
SergeantCyrano
@SergeantCyrano
Nov 07 2016 05:24 UTC
Sup, guys?
Yackbz
@Yackbz
Nov 07 2016 06:00 UTC
has anybody a solution for assignment 10?
sampath484
@sampath484
Nov 07 2016 06:08 UTC
Hey !
D O R C ¥
@Dorcy-ndg3
Nov 07 2016 06:11 UTC
@yannick3110 10 is probably your number of brownies,, what is the name of the challenge??
sumit kumar
@sumit-prgmr
Nov 07 2016 06:12 UTC
can anyone solve stand in line challange
Eldar Tinjić
@EldarT90
Nov 07 2016 06:16 UTC
Hello anyone here setup angular 2 + ionic 2 + meteor without bugs?
Markus Kiili
@Masd925
Nov 07 2016 06:19 UTC
@sumit-prgmr Find out the two array methods that do those things asked and use them on arr and item.
javescript
@javescript
Nov 07 2016 06:20 UTC
lol im back
sumit kumar
@sumit-prgmr
Nov 07 2016 06:21 UTC
thanks @Masd925
CamperBot
@camperbot
Nov 07 2016 06:21 UTC
sumit-prgmr sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2847 | @masd925 |http://www.freecodecamp.com/masd925
javescript
@javescript
Nov 07 2016 06:22 UTC

is this a good start <!DOCTYPE html>

<html>
<head>
<title>blank</title>
</head>
<body>
<h1>blank</h1>
<h1>blank</h1>
<div>
<h2>blank.
<a href="https://www.youtube.com/channel/UCXNcetYogdh6OMfZfkLoNHg">Click Here.</a>
</div>
<p>Make Sure To Credit Me</p><a href="https://www.youtube.com/channel/UCXNcetYogdh6OMfZfkLoNHg">Click Here.</a>
<div>
blank
</div>
<div>
<h2>blank</h2>
</div>
<div>
copyright © 2016 Logan Mullen
</body>
</html>

D O R C ¥
@Dorcy-ndg3
Nov 07 2016 06:32 UTC
@javescript there is a paragraph u dint close
but its good
Shishi Wang
@janesuit
Nov 07 2016 06:34 UTC
hello. everyone
Tsulatsi Tamim
@tsulatsitamim
Nov 07 2016 06:37 UTC
``````
AbbyLOL
@AbbyLOL
Nov 07 2016 06:38 UTC
ok I give up I don;t know how to do the using objets for lookups
Tsulatsi Tamim
@tsulatsitamim
Nov 07 2016 06:38 UTC

function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  function falshyFilter(value) {
    if (value === false || value === null || value === 0 || value === '' || value === undefined || value == 'NaN' ) {
      return false; 
    }
    else return true;
  }
  return arr.filter(falshyFilter);
}

bouncer([7, "ate", "", false, 9]);
i still get wrong with my NaN, does anybody know?
AbbyLOL
@AbbyLOL
Nov 07 2016 06:38 UTC
help anybody
CamperBot
@camperbot
Nov 07 2016 06:38 UTC
no wiki entry for: anybody
Dan Couper
@DanCouper
Nov 07 2016 06:40 UTC
Why have you created two more variables, key and str? You have result, you never assign anything to that, instead assigning to those new variables you created and never use.
Coy Sanders
@coymeetsworld
Nov 07 2016 06:41 UTC
@AbbyLOL you don't need the key value
that's your val parameter in the function
Dan Couper
@DanCouper
Nov 07 2016 06:41 UTC
@tsulatsitamim NaN is not equal to anything, not even NaN
you cannot check if value == ‘NaN’ because even if value is NaN it isn’t exual to NaN
Tsulatsi Tamim
@tsulatsitamim
Nov 07 2016 06:43 UTC
@DanCouper here the test result http://prntscr.com/d42eel
@DanCouper is there any solution?
Dan Couper
@DanCouper
Nov 07 2016 06:43 UTC
NaN is basically saying that JS thinks that whatever has that value should be a number, but it cannot read it as a number
NaN is not equal to anything, not even NaN
value !== value
NaN !== Nan is true
value !== value checks that a primitive value is NaN
and value === value will check that a primitive value isn’t NaN
Tsulatsi Tamim
@tsulatsitamim
Nov 07 2016 06:46 UTC
@DanCouper It solved, thank you for your explanation. really appreciate that
CamperBot
@camperbot
Nov 07 2016 06:46 UTC
tsulatsitamim sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 347 | @dancouper |http://www.freecodecamp.com/dancouper
Dan Couper
@DanCouper
Nov 07 2016 06:46 UTC
:thumbsup:
You can also just use Boolean(value)
insted of the long conditional
Jeremy Eckstein
@exstein
Nov 07 2016 06:47 UTC
Hello. I am trying to return the largest numbers from each array for this challenge, but I'm not even sure where to start.
Dan Couper
@DanCouper
Nov 07 2016 06:47 UTC
return arr.filter(function(value) { return Boolean(value))
or just
return arr.filter(Boolean)
because Boolean converts “falsey” values (0, ’’, false, null, NaN, undefined, -0) to false
朝霞落日
@William-WFC
Nov 07 2016 06:50 UTC
大家好
Amro
@amroalmusharaf
Nov 07 2016 06:51 UTC
hey guys, anyone free to lend me a hand with the card counting javascript challenge?
Dan Couper
@DanCouper
Nov 07 2016 06:52 UTC
@exstein write a function that gets the largest value from one array - it should take one array as an argument, and return the largest number in that array. Then run that function for every array in the main array (map is useful here).
Amro
@amroalmusharaf
Nov 07 2016 06:55 UTC

here's what i've got so far, if someone has a minute to give it a look? kind of hit a wall, not sure what i'm missing:

var count = 0;

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

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

help
Varun Talluri
@talluri-crm
Nov 07 2016 07:04 UTC
@amroalmusharaf Try this
@amroalmusharaf if (count > 0) answer = " Bet";
return "" + count + answer;
Varun Talluri
@talluri-crm
Nov 07 2016 07:11 UTC

@AbbyLOL it should be var lookup instead of obj. var lookup = {
"alpha": "Adams",
"bravo": "Boston",
"charlie": "Chicago",
"delta": "Denver",
"echo": "Easy",
"foxtrot": "Frank"
};

result = lookup[val];

Amro
@amroalmusharaf
Nov 07 2016 07:24 UTC
thanks @talluri-crm - that did the trick.
CamperBot
@camperbot
Nov 07 2016 07:24 UTC
amroalmusharaf sends brownie points to @talluri-crm :sparkles: :thumbsup: :sparkles:
:cookie: 209 | @talluri-crm |http://www.freecodecamp.com/talluri-crm
skingyan
@skingyan
Nov 07 2016 07:27 UTC
Profile Lookup
Markus Kiili
@Masd925
Nov 07 2016 07:28 UTC
@skingyan Having problems?
skingyan
@skingyan
Nov 07 2016 07:29 UTC
@Masd925 yes ,can you help me?thx
Markus Kiili
@Masd925
Nov 07 2016 07:30 UTC
@skingyan What have you got so far? Post the code you have done.
skingyan
@skingyan
Nov 07 2016 07:31 UTC

@Masd925 >//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

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

if (contacts[i].firstName === firstName && contacts[i].prop !==undefined ){
    return contacts[i].prop;

}else if (contacts[i].firstName !==firstName){

  return "No such contact";

}else if (contacts[i].prop ===undefined) {

  return "No such property";
}

}
// Only change code above this line
}

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

Markus Kiili
@Masd925
Nov 07 2016 07:32 UTC
@skingyan Property existence test should be done with .hasOwnProperty() or .propertyIsEnumerable()
.prop looks for property key "prop". Use bracket notation instead when you have the key in a variable.
The simplest structure is two nested if's inside the contact loop. Firstname test and property existence test.
You code can return No such contact after checking only one contact, so the logic has problems.
skingyan
@skingyan
Nov 07 2016 07:35 UTC
ok , thx very much , I will try
@Masd925 ok , thx very much , I will try
CamperBot
@camperbot
Nov 07 2016 07:35 UTC
skingyan sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2848 | @masd925 |http://www.freecodecamp.com/masd925
Toyco
@Toyco
Nov 07 2016 07:56 UTC
Literally on the same problem as skingyan
lucky timing
Markus Kiili
@Masd925
Nov 07 2016 07:57 UTC
@Toyco You really only need the loop, two nested if's and the returns on correct spots.
Toyco
@Toyco
Nov 07 2016 07:57 UTC
if (firstName !== null && prop !== null); { return firstName.prop; } if (firstName === null);{ return "No such contact"; } if (prop === null);{ return "No such property";
oh I forgot how to do the blackbox again
isn't it ```?
  if (firstName !== null && prop !== null); {
      return firstName.prop;
      }
  if (firstName === null);{
    return "No such contact";
  }
  if (prop === null);{
    return "No such property";
there we go
and you're saying make a loop with two nested ifs?
Markus Kiili
@Masd925
Nov 07 2016 07:59 UTC
@Toyco First thing is to loop or iterate through contacts array.
Toyco
@Toyco
Nov 07 2016 08:00 UTC
I'm really bad at looping arrays..
is this one of those for (i=0;something.length>i;i++) things?
Markus Kiili
@Masd925
Nov 07 2016 08:01 UTC
@Toyco Some errors there. Look at the earlier challenge on looping array indices.
Toyco
@Toyco
Nov 07 2016 08:03 UTC
for (var i=0; i < contacts.length; i++) {
console.log(contacts[i]);
}
Markus Kiili
@Masd925
Nov 07 2016 08:04 UTC
@Toyco Yes.
izakibikas
@izakibikas
Nov 07 2016 08:04 UTC
@Toyco , you're on the right path
Toyco
@Toyco
Nov 07 2016 08:04 UTC
but instead of console.log have it return contact[array inside?]
Markus Kiili
@Masd925
Nov 07 2016 08:04 UTC
@Toyco Then make two nested if's inside the contact loop.
abbas ashraf mughal
@abbasashraf
Nov 07 2016 08:04 UTC
var date = new Date
date.setFullYear(1992).setMonth(8).setDate(14).setHours(12).setMinutes(30);
it will work or not ???
Markus Kiili
@Masd925
Nov 07 2016 08:05 UTC
@Toyco First if should check if the firstName property value of the looped contact equals the value of firstName parameter.
Toyco
@Toyco
Nov 07 2016 08:05 UTC
wait so do I make it return contact[i] so it keep iterating through it, and then go make the ifs?
the main trouble I'm having is with the looping through array and understanding how it works
what I have currently would display on the console the entire array.. right?
Markus Kiili
@Masd925
Nov 07 2016 08:06 UTC
@Toyco You make tests on the looped contact and return when you know the return value.
Toyco
@Toyco
Nov 07 2016 08:06 UTC
but for testing the console.log has to change to return
Markus Kiili
@Masd925
Nov 07 2016 08:07 UTC
@Toyco Second if should check whether the looped contact has the property key stored in parameter prop. Use .hasOwnProperty() method.
abbas ashraf mughal
@abbasashraf
Nov 07 2016 08:07 UTC
var date = new Date
date.setFullYear(1992).setMonth(8).setDate(14).setHours(12).setMinutes(30);
it will work or not ???
Toyco
@Toyco
Nov 07 2016 08:09 UTC
for (var i=0; i < contacts.length; i++) {
  if (firstName.hasOwnProperty() === true);
     return firstName.prop;

}
Markus Kiili
@Masd925
Nov 07 2016 08:09 UTC
@abbasashraf No, because for example .setFullYear() returns a number.
Toyco
@Toyco
Nov 07 2016 08:09 UTC
that would return firstName.prop if it has it's own property correct?
Markus Kiili
@Masd925
Nov 07 2016 08:09 UTC
@Toyco Look at my post about the first if. It should be the firstName test.
izakibikas
@izakibikas
Nov 07 2016 08:10 UTC
@Toyco , you don't use a semicolon after an if statement
Toyco
@Toyco
Nov 07 2016 08:11 UTC
alright, so am I not checking the value of the property with firstName.prop?
or returning it if it's true?
Jeff Shapiro
@Jeff-Shapiro
Nov 07 2016 08:11 UTC
@Toyco theres a few things wrong with your code
Markus Kiili
@Masd925
Nov 07 2016 08:11 UTC
@Toyco Check whether the .firstName property value of the looped contact equals the firstName parameter.
Jeff Shapiro
@Jeff-Shapiro
Nov 07 2016 08:11 UTC
=== true is redundant
your missing a set of {}
Toyco
@Toyco
Nov 07 2016 08:12 UTC
@Jeff-Shapiro I'm just trying to think through the problem not the syntax atm
Jeff Shapiro
@Jeff-Shapiro
Nov 07 2016 08:12 UTC
then I suggest writing in pseudo code and not poorly coded workings
Markus Kiili
@Masd925
Nov 07 2016 08:13 UTC
@Toyco First if checks if the looped contact is the one with the correct first name. Second if checks whether the contact has the property key.
Toyco
@Toyco
Nov 07 2016 08:14 UTC
@Jeff-Shapiro what do you mean === true is redundant btw?
does === just work without the true?
izakibikas
@izakibikas
Nov 07 2016 08:15 UTC
if(somethingThatReturnsTrue) is all you need, you don't need to compare @Toyco
Toyco
@Toyco
Nov 07 2016 08:15 UTC
ah alright
izakibikas
@izakibikas
Nov 07 2016 08:15 UTC
something that returns boolean* , my bad
Sajeetharan
@sajeetharan
Nov 07 2016 08:16 UTC
anyone worked with fbsdk?
Toyco
@Toyco
Nov 07 2016 08:16 UTC
easiest way for me to think about that is compare, but good note for the future
for (var i=0; i < contacts.length; i++) {
  if (firstName === null){
    return "No such contact";
  }
  if (firstName.hasOwnProperty === true){
    return firstName.prop;
  }
}
so is that what you mean by two ifs with first seeing if it exists
and second seeing if it has own property?
Markus Kiili
@Masd925
Nov 07 2016 08:18 UTC
@Toyco Don't compare firstName to null. Compare it to the firstName property of the looped contact.
Toyco
@Toyco
Nov 07 2016 08:18 UTC
firstName.hasOwnProperty === firstName.prop?
Sam Nejad
@hesamnejad
Nov 07 2016 08:19 UTC
Markus Kiili
@Masd925
Nov 07 2016 08:19 UTC
@Toyco That is not the syntax of hasOwnProperty.
It is obj.hasOwnProperty(key)
Toyco
@Toyco
Nov 07 2016 08:19 UTC
so firstName.hasOwnProperty returns true or false
oh
so firstName.hasOwnProperty(prop)?
Markus Kiili
@Masd925
Nov 07 2016 08:20 UTC
firstName is not the looped object
Toyco
@Toyco
Nov 07 2016 08:20 UTC
what is then?
i?
contact?
Markus Kiili
@Masd925
Nov 07 2016 08:20 UTC
How do you get the array element (=one contact)
Toyco
@Toyco
Nov 07 2016 08:21 UTC
I'm not sure
Jeff Shapiro
@Jeff-Shapiro
Nov 07 2016 08:21 UTC
@Toyco
if (firstName.hasOwnProperty === true) 
<!-- is the same as -->
if (firstName.hasOwnProperty)
Markus Kiili
@Masd925
Nov 07 2016 08:21 UTC
If arr is an array arr[i] is an array element.
Toyco
@Toyco
Nov 07 2016 08:21 UTC
ok
so I'm looking for contacts[element]
Markus Kiili
@Masd925
Nov 07 2016 08:22 UTC
contacts[i] is one contact.
ashleypt
@ashleypt
Nov 07 2016 08:22 UTC
hi im on profile lookup as well
Markus Kiili
@Masd925
Nov 07 2016 08:22 UTC
@ashleypt Look at the posts above about the challenge if you have problems.
Toyco
@Toyco
Nov 07 2016 08:23 UTC
so to make sure, the code I want is a for loop that goes through all contact elements, and then I test to see if the element exists, and if it does then see if it has it's own property
right?
ashleypt
@ashleypt
Nov 07 2016 08:24 UTC
ok I did my problem is a bit different... here's my code
for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].hasOwnProperty(prop) && contacts[i].firstName === firstName) {
      return contacts[i][prop];
    } else if (!contacts[i].hasOwnProperty(prop)) {
      return "No such property"
    } else {
      return "No such contact";
    }
  }
Markus Kiili
@Masd925
Nov 07 2016 08:24 UTC
@Toyco You check whether the looped contact has the correct firstname and whether it has the property key.
@ashleypt Your code can return No such contact after checking only one contact.
ashleypt
@ashleypt
Nov 07 2016 08:25 UTC
unfortunately, when I test it with "Kristian" "lastName" it says no contact
oh yeah! thanks markus
Markus Kiili
@Masd925
Nov 07 2016 08:25 UTC
@ashleypt The simplest structure is two nested if's for those two tests. Avoids repeating conditions.
ashleypt
@ashleypt
Nov 07 2016 08:26 UTC
so if the firstName is matching, then check if the property exists
should I set a boolean variable outside the for loop for whether the prop exists and whether the contact exists and set them to true if one of them is found?
or if the contact doesnt exist is that what I should report even if the prop exists
Markus Kiili
@Masd925
Nov 07 2016 08:27 UTC
@ashleypt You only need those if's and returns on correct spots.
ashleypt
@ashleypt
Nov 07 2016 08:27 UTC
hmm ill solve it then...
thanks
Markus Kiili
@Masd925
Nov 07 2016 08:27 UTC
@ashleypt It will take some head scratching to get those right.
ashleypt
@ashleypt
Nov 07 2016 08:27 UTC
yeah
Brent Liu
@TeaCrab
Nov 07 2016 08:28 UTC
Hello
I'm stuck here, having TypeError: testArr.shift is not a function
Jeff Shapiro
@Jeff-Shapiro
Nov 07 2016 08:28 UTC
@ashleypt do you know how to use console.log or alert for debugging?
Brent Liu
@TeaCrab
Nov 07 2016 08:29 UTC
function nextInLine(arr, item) {
// Your code here
testArr = arr.push(item);
return testArr.shift(); // Change this line
}
ashleypt
@ashleypt
Nov 07 2016 08:29 UTC
@Jeff-Shapiro yeah, you can log the contents of any variable with console.log
Toyco
@Toyco
Nov 07 2016 08:29 UTC
for (var i=0; i < contacts.length; i++) {
  if (contacts[i].hasOwnProperty(prop)){
    return prop;
  }
  if (that isn't the case){
      return "No such contact" or "No such property"
      }
}
am I thinking this through right?
shenjiuer
@shenjiuer
Nov 07 2016 08:29 UTC
help, the error is it is an infinite loop when the arguments is 977
function sumPrimes(num) {
  var arr=[];
  for(var i=2;i<=num;i++){
    for(var j=2;j<i;j++){
      if(i%j==0)break;
    }
    if(j>=i){
      arr.push(i);
    }
  }
  return arr.reduce(function(a,b){
    return a+b;
  });
}

sumPrimes(977);
CamperBot
@camperbot
Nov 07 2016 08:29 UTC
no wiki entry for: the error is it is an infinite loop when the arguments is 977function sumprimesnum var arr forvar i2inumi forvar j2jij ifij0break ifji arrpushi return arrreducefunctionab return ab sumprimes977
ashleypt
@ashleypt
Nov 07 2016 08:30 UTC
@Toyco no then you have the same problem as me
Toyco
@Toyco
Nov 07 2016 08:30 UTC
what's that problem?
ashleypt
@ashleypt
Nov 07 2016 08:30 UTC
OH!
umm the problem is that it can return false after checking only the first contact
it has to go through them all
Toyco
@Toyco
Nov 07 2016 08:31 UTC
hmm
ashleypt
@ashleypt
Nov 07 2016 08:31 UTC
I see... the no such returns go AFTER the for loop
Toyco
@Toyco
Nov 07 2016 08:31 UTC
ah that makes sense
Brent Liu
@TeaCrab
Nov 07 2016 08:31 UTC
function nextInLine(arr, item) {
// Your code here
testArr = arr.push(item);
return testArr.shift(); // Change this line
}
ashleypt
@ashleypt
Nov 07 2016 08:31 UTC
but how do we know which one
Brent Liu
@TeaCrab
Nov 07 2016 08:31 UTC
This gives me the same result
ashleypt
@ashleypt
Nov 07 2016 08:31 UTC
oh I see!
Brent Liu
@TeaCrab
Nov 07 2016 08:31 UTC
sorry one sec
that was wrong
ashleypt
@ashleypt
Nov 07 2016 08:31 UTC
inside the nested if loop that checks if the contact has a property if it doesn't then you return no such prop
then outside the for loop no other returns occurred so you can return no such contact
damn that's brilliant, that was a good exercise
if you still have trouble @Toyco ill show my solution and help explain it :) it's a tough one
Brent Liu
@TeaCrab
Nov 07 2016 08:32 UTC
function nextInLine(arr, item) {
  // Your code here
  testArr = arr.push(item);
  x = testArr.shift();
  return x;  // Change this line
}
Toyco
@Toyco
Nov 07 2016 08:32 UTC
I haven't been able to solve it for a week now with little spare time
Markus Kiili
@Masd925
Nov 07 2016 08:33 UTC
@ashleypt You can also do it elegantly with .reduce().
Brent Liu
@TeaCrab
Nov 07 2016 08:33 UTC
This give me the same TypeError testArr.shift is not a function
ashleypt
@ashleypt
Nov 07 2016 08:33 UTC
oh yeah I saw funfunfunction's video on it, can you show an example?
@Toyco try what I suggested, here's some pseudo code
for contact in contacts
Markus Kiili
@Masd925
Nov 07 2016 08:34 UTC
@ashleypt You should look at simple examples on MDN reduce page.
ashleypt
@ashleypt
Nov 07 2016 08:34 UTC
if contact is correct firstname then
if contact has the property return the property else return no property found
end for loop
return no such contact
@Toyco that pseudo code should help
it has an if inside an if like the for loops have nested for loops
@Masd925 thanks, ill check that out :)
CamperBot
@camperbot
Nov 07 2016 08:35 UTC
ashleypt sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2849 | @masd925 |http://www.freecodecamp.com/masd925
ashleypt
@ashleypt
Nov 07 2016 08:36 UTC
yeah my solution worked @Toyco
Markus Kiili
@Masd925
Nov 07 2016 08:37 UTC
@TeaCrab Use arr and item, not testArr. It is only for FCC tests.
Jeff Shapiro
@Jeff-Shapiro
Nov 07 2016 08:39 UTC
@ashleypt even your psuedo code has logic errors lol
Ryan VanDyke
@ryanjvandyke
Nov 07 2016 08:39 UTC
does anyone here have any other resources to learn JavaScript? I mean reaaaallly basic stuff. I love FCC but getting super hung up left and right in the realms of JS and would just like some other means of learning it. Not done here at all, just trying to be flexible in my learning lol.
ashleypt
@ashleypt
Nov 07 2016 08:39 UTC
@Masd925 so a solution with reduce would have the accumulator be "No such contact", and then the callback returns the property if it exists or no such property if it doesn't? then you return the results of running the reduce function?
@Jeff-Shapiro my actual code worked though
Jeff Shapiro
@Jeff-Shapiro
Nov 07 2016 08:40 UTC
@ryanjvandyke try tutorialspoint
Toyco
@Toyco
Nov 07 2016 08:41 UTC
for (var i=0; i < contacts.length; i++) {
  if (contacts[i] === firstName) {
    if (contacts[i].hasOwnProperty) {
      return prop;}
    else if(true) {
      return "No property found";
      }
    }
  }
}
return "No such contact";
ok I know I'm messing up something, but I"m not sure what
ashleypt
@ashleypt
Nov 07 2016 08:42 UTC
for(var i = 0; i < contacts.length; i++) {
  if(contacts[i].firstName == firstName) {
    if(contacts[i].hasOwnProperty(prop)) return contacts[i][prop];
    else return "No such property";
  }
}
return "No such contact";
Toyco
@Toyco
Nov 07 2016 08:42 UTC
still getting used to else in javascript coming from python elif's lol
ashleypt
@ashleypt
Nov 07 2016 08:42 UTC
but you should try to understand why that works
@Toyco python uses else too
Toyco
@Toyco
Nov 07 2016 08:43 UTC
yes but different formatting from javascript
ashleypt
@ashleypt
Nov 07 2016 08:43 UTC
:)
Toyco
@Toyco
Nov 07 2016 08:43 UTC
does it's own {}'s lol
ashleypt
@ashleypt
Nov 07 2016 08:43 UTC
yeah haha
a lot of statements dont need them if there's only one statement but it's bad style
Toyco
@Toyco
Nov 07 2016 08:44 UTC
fun doing the problem with you @ashleypt
ashleypt
@ashleypt
Nov 07 2016 08:44 UTC
@Toyco likewise but do you understand why that works?
Toyco
@Toyco
Nov 07 2016 08:44 UTC
ya
Markus Kiili
@Masd925
Nov 07 2016 08:45 UTC
@ashleypt Yes.
Toyco
@Toyco
Nov 07 2016 08:45 UTC
now I only have one thing left in the javascript to do
basic javascript at least lol
ashleypt
@ashleypt
Nov 07 2016 08:45 UTC
@Toyco im gonna try solving it with reduce now
thats intermediate I guess
Toyco
@Toyco
Nov 07 2016 08:46 UTC
I saw that as an option when I was looking into the problem
ashleypt
@ashleypt
Nov 07 2016 08:46 UTC
I imagine advanced is like promises and factories and the other stuff I see funfunfunction post
Toyco
@Toyco
Nov 07 2016 08:46 UTC
but my main trouble is the formatting of for loop and if statements
for arrays at least
ashleypt
@ashleypt
Nov 07 2016 08:46 UTC
it's just practice
Markus Kiili
@Masd925
Nov 07 2016 08:46 UTC
Reduce, the faucet and the goose of array iteration
ashleypt
@ashleypt
Nov 07 2016 08:46 UTC
try writing the kind that give you trouble over and over
Toyco
@Toyco
Nov 07 2016 08:47 UTC
well I gtg, catch ya later
ashleypt
@ashleypt
Nov 07 2016 08:48 UTC
seeya :)
michael
@gfear
Nov 07 2016 08:52 UTC
i am having an issue with the testin objects for properties lesson

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

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

}

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

i am missing the part where it displays Not Found if it is not in the list
nvm lol i have to go
ashleypt
@ashleypt
Nov 07 2016 08:59 UTC
here's my profile lookup code with reduce, which also works @Masd925 - thanks again :)
CamperBot
@camperbot
Nov 07 2016 08:59 UTC
ashleypt sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: ashleypt already gave masd925 points
tangwen
@xinbeimousha
Nov 07 2016 09:00 UTC
hello,I'm stuck here,Chunky Monkey
Ramesh syangtan
@rameshsyn
Nov 07 2016 09:01 UTC
@gfear first if condition is always true , so it will not go to else section
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Here

if (myObj.hasOwnProperty(checkProp)) {
return myObj[checkProp];
} else{
return "Not Found";
}
}
// Test your code by modifying these values
checkObj("gift");
try this code
Markus Kiili
@Masd925
Nov 07 2016 09:02 UTC
@ashleypt Did it work?
ashleypt
@ashleypt
Nov 07 2016 09:02 UTC
@Masd925 yes :)
Markus Kiili
@Masd925
Nov 07 2016 09:04 UTC
@ashleypt Same as my reduce solution, except that I used ternary operators instead of those if's.
Abhisek Pattnaik
@abhisekp
Nov 07 2016 09:05 UTC
bad ternary pew pew :paw_prints:
ashleypt
@ashleypt
Nov 07 2016 09:06 UTC
@Masd925 nice, I should get in the habit of using those when possible
Markus Kiili
@Masd925
Nov 07 2016 09:06 UTC
@abhisekp You finally made that software that alerts you when someone uses bad words like ternary?
Abhisek Pattnaik
@abhisekp
Nov 07 2016 09:06 UTC
:D
ashleypt
@ashleypt
Nov 07 2016 09:07 UTC
so like this?
return value.hasOwnProperty(prop) ? value[prop] : "No such property";
yeah still worked
kirbyedy
@kirbyedy
Nov 07 2016 09:09 UTC
why is ternary bad ?
Abhisek Pattnaik
@abhisekp
Nov 07 2016 09:10 UTC
um.m... err... i dunno... but people use it badly sometimes
arg ? (arg = 2) : 0
kirbyedy
@kirbyedy
Nov 07 2016 09:10 UTC
so its the people, not the ternary operator then is it ? :)
Abhisek Pattnaik
@abhisekp
Nov 07 2016 09:11 UTC
:D
kirbyedy
@kirbyedy
Nov 07 2016 09:11 UTC
sweet mother of jesus what the hell is that !?
Abhisek Pattnaik
@abhisekp
Nov 07 2016 09:11 UTC
LOLOL
told ya... .people can be weird sometimes
Alexander Domikov
@AlexanderDom
Nov 07 2016 09:23 UTC
or simply they not entirely understand it :)
Johnny
@JohnnyBizzel
Nov 07 2016 09:25 UTC
@kirbyedy If you nest Ternary operators it makes code hard to read. But who does that?!
Abhisek Pattnaik
@abhisekp
Nov 07 2016 09:28 UTC
yeah!
Ternary Operator - Boon or Bane for JS Devs. Discuss.
Johnny
@JohnnyBizzel
Nov 07 2016 09:30 UTC
I like it for short statements. For longer expressions I prefer to write out an if else block
Alexander Domikov
@AlexanderDom
Nov 07 2016 09:30 UTC
someone like to write their code in one line too, it depends if you want your code to be understood by someone else or future you :)
Johnny
@JohnnyBizzel
Nov 07 2016 09:32 UTC
:D
Sorin Ruse
@sorinr
Nov 07 2016 09:32 UTC
is the ternary executed faster then the traditional if-else?
Abhisek Pattnaik
@abhisekp
Nov 07 2016 09:33 UTC
where are the braces?
Oh! It's the right hand side design :D
Annika Williamson
@AnnikaKW
Nov 07 2016 09:33 UTC
I have a question about "Profile Lookup". The predefined function lookUpProfile contains a concrete key (firstName) and a standin for all keys (prop). This is messing me up somehow... If I test whether lastName (say, "Kristian") is an actual value of lastName in the array, I run into a weird situation. This is my code for this test (which doesn't work): if (contacts[i].firstName == firstName) Can someone tell I'm going wrong in my logic?
Johnny
@JohnnyBizzel
Nov 07 2016 09:34 UTC
@sorinr Probably yes as the code parser has less work to do.
Johnny
@JohnnyBizzel
Nov 07 2016 09:35 UTC
@AnnikaKW Can you share the whole code?
Alexander Domikov
@AlexanderDom
Nov 07 2016 09:35 UTC
@AnnikaKW i don't remember exactly exercice but you triyng to see if for exemple contacts[0]["Alex"] === "Alex"
Annika Williamson
@AnnikaKW
Nov 07 2016 09:36 UTC
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


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

    if (contacts[i].hasOwnProperty[prop] && contacts[i][firstName] == firstName) {
      value = contacts[i][prop];
      return value;
    }
    else if (!contacts[i].hasOwnProperty[prop]) {
      return "No such property";
    }

  }
// Only change code above this line
}
Sorin Ruse
@sorinr
Nov 07 2016 09:36 UTC
@JohnnyBizzel in a larger js file i can see its benefits. it can make ur code smaller and the loading will be faster
Alexander Domikov
@AlexanderDom
Nov 07 2016 09:37 UTC
@AnnikaKW it's three `
not two ;)
Annika Williamson
@AnnikaKW
Nov 07 2016 09:37 UTC
Ah sorry :(
Alexander Domikov
@AlexanderDom
Nov 07 2016 09:37 UTC
you can edit it
at right of time of message
better :)
Annika Williamson
@AnnikaKW
Nov 07 2016 09:38 UTC
thanks @AlexanderDom
CamperBot
@camperbot
Nov 07 2016 09:38 UTC
annikakw sends brownie points to @alexanderdom :sparkles: :thumbsup: :sparkles:
:cookie: 390 | @alexanderdom |http://www.freecodecamp.com/alexanderdom
Alexander Domikov
@AlexanderDom
Nov 07 2016 09:38 UTC
you're welcome
Johnny
@JohnnyBizzel
Nov 07 2016 09:39 UTC
@AnnikaKW I think you are making the common mistake which is returning inside the for loop.
Abhisek Pattnaik
@abhisekp
Nov 07 2016 09:40 UTC

in a larger js file i can see its benefits. it can make ur code smaller and the loading will be faster

loading is a one off thing. small code doesn't always mean faster code. It might be completely opposite to that while taking into account the execution speed

Alexander Domikov
@AlexanderDom
Nov 07 2016 09:41 UTC
if you minify your css and js its not so significant i think
Annika Williamson
@AnnikaKW
Nov 07 2016 09:41 UTC
How would you do an if/else structure inside a for loop without returning?
Abhisek Pattnaik
@abhisekp
Nov 07 2016 09:41 UTC
yeah!
how would you do it outside without returning? @AnnikaKW
Johnny
@JohnnyBizzel
Nov 07 2016 09:42 UTC
@AnnikaKW Just checking something...
Sorin Ruse
@sorinr
Nov 07 2016 09:43 UTC
@abhisekp :+1: I'm just an old guy and i've learnd about conditionals too many years ago during my univ years (was using fortran and cobol by that time) but for me when i see some conditionals (if-else) on a page i just get the picture(not all the time :) ) of what is supposed to happen there
Johnny
@JohnnyBizzel
Nov 07 2016 09:43 UTC
@AnnikaKW Try this instead contacts[i].firstName == firstName
Annika Williamson
@AnnikaKW
Nov 07 2016 09:44 UTC
@JohnnyBizzel I had that option before, it failed the test too
Alexander Domikov
@AlexanderDom
Nov 07 2016 09:44 UTC
normally there are no problem with []
problem must come somewhere else
Johnny
@JohnnyBizzel
Nov 07 2016 09:44 UTC
@AnnikaKW It is failing because of the second return statement
Abhisek Pattnaik
@abhisekp
Nov 07 2016 09:45 UTC
:scream: :scream_cat:
wow! @sorinr :D
Annika Williamson
@AnnikaKW
Nov 07 2016 09:46 UTC
@JohnnyBizzel You'll have to explain that one to me, because the only test that works is when prop is not a real property of any object, which is what the else if is supposed to test for.
Alexander Domikov
@AlexanderDom
Nov 07 2016 09:47 UTC
@AnnikaKW you could write it like this by the way
// still don't work ><
    if (contacts[i].hasOwnProperty[prop]) {
      if(contacts[i][firstName] == firstName){
        value = contacts[i][prop];
        return value;
      }    
    } else {
      return "No such property";
    }
Annika Williamson
@AnnikaKW
Nov 07 2016 09:48 UTC
@AlexanderDom I could, but isn't that the same thing?
Johnny
@JohnnyBizzel
Nov 07 2016 09:48 UTC
@AnnikaKW My mistake. This is the corrent syntax...contacts[i].hasOwnProperty(prop) use parenthesis not square brackets
Sorin Ruse
@sorinr
Nov 07 2016 09:48 UTC
@abhisekp yep. that old i am :)
Jack Cox
@Jack-Cox98
Nov 07 2016 09:48 UTC
I'm having trouble with 'Return Early pattern for Functions', my code has no errors but it's not returning anything above 0, could someone help? Thankyou

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

  // Only change code above this line

  return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}
// Change values below to test your code
abTest(3,3);
Alexander Domikov
@AlexanderDom
Nov 07 2016 09:48 UTC
just little bit shorter without other else if
Chandrahas P
@Chan11
Nov 07 2016 09:50 UTC
@Jack-Cox98 this is wrong if (a < 0 || b < 0);
Annika Williamson
@AnnikaKW
Nov 07 2016 09:50 UTC
@JohnnyBizzel Oh my gosh! What a simple solution. I guess that's how it usually turns out... Thanks so much.
CamperBot
@camperbot
Nov 07 2016 09:50 UTC
annikakw sends brownie points to @johnnybizzel :sparkles: :thumbsup: :sparkles:
:cookie: 766 | @johnnybizzel |http://www.freecodecamp.com/johnnybizzel
Jack Cox
@Jack-Cox98
Nov 07 2016 09:51 UTC
@Chan11 okay thanks, any suggestions?
CamperBot
@camperbot
Nov 07 2016 09:51 UTC
jack-cox98 sends brownie points to @chan11 :sparkles: :thumbsup: :sparkles:
:cookie: 316 | @chan11 |http://www.freecodecamp.com/chan11
Johnny
@JohnnyBizzel
Nov 07 2016 09:51 UTC
@AnnikaKW Let me know if it passes. I think there may be another problem...(?)
Chandrahas P
@Chan11
Nov 07 2016 09:53 UTC
@Jack-Cox98
 return  (a < 0 || b < 0) ? undefined : Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
Abhisek Pattnaik
@abhisekp
Nov 07 2016 09:54 UTC
@Chan11 umm.... we're not supposed to do that
Annika Williamson
@AnnikaKW
Nov 07 2016 09:56 UTC
@JohnnyBizzel Right, there is. I need to figure out how to test for the case that something matches none of the objects in an array. (It's easier to find one that does match.)
But if x && y line above does work now.
Chandrahas P
@Chan11
Nov 07 2016 09:56 UTC
@abhisekp is that wrong ,why ?
Johnny
@JohnnyBizzel
Nov 07 2016 09:56 UTC
@AnnikaKW Do this outside the for loop
Abhisek Pattnaik
@abhisekp
Nov 07 2016 09:57 UTC
@Chan11 the question asks to use return early pattern
Annika Williamson
@AnnikaKW
Nov 07 2016 09:57 UTC
@JohnnyBizzel So returning the one time after the if statement is okay inside the loop, no?
Alexander Domikov
@AlexanderDom
Nov 07 2016 09:58 UTC
@AnnikaKW i found a little modification
it's if(contacts[i]["firstName"] === firstName){
Johnny
@JohnnyBizzel
Nov 07 2016 09:58 UTC

@AnnikaKW Yes. As soon as you find what you are looking for, return the result:

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

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

Alexander Domikov
@AlexanderDom
Nov 07 2016 09:59 UTC
or like i said before you testing for contacts[i]["Akira"] === "Akira"
Chandrahas P
@Chan11
Nov 07 2016 09:59 UTC
@abhisekp yeah thats right :+1: :smile:
Samiullah Khan
@technbuzz
Nov 07 2016 10:03 UTC
Hi All, I need help with US Phone Number algorithm.
Is it must to use one regular expression?
Or can we pass a string to more that one regular expression?
Abhisek Pattnaik
@abhisekp
Nov 07 2016 10:05 UTC
@technbuzz you may use multiple regex. :white_check_mark: :+1:
Chandrahas P
@Chan11
Nov 07 2016 10:06 UTC
@technbuzz try to learn and use regex,it will help you alot in many situations
Samiullah Khan
@technbuzz
Nov 07 2016 10:06 UTC
@Chan11 I am using regex but can solve exercise using just one regexp pattern.
can't solve the country code part @abhisekp @Chan11
Abhisek Pattnaik
@abhisekp
Nov 07 2016 10:07 UTC
yes you can solve using one regex but you may solve using multiple regexes
Oniichan
@ProjectOU
Nov 07 2016 10:07 UTC
Abhisek Pattnaik
@abhisekp
Nov 07 2016 10:08 UTC
Wow! A video :D
Oniichan
@ProjectOU
Nov 07 2016 10:08 UTC
help me .. when i click the first button .. everyone gets send
CamperBot
@camperbot
Nov 07 2016 10:08 UTC
no wiki entry for: me when i click the first button everyone gets send
Oniichan
@ProjectOU
Nov 07 2016 10:08 UTC
:(
when i click the first button everyone gets send
Samiullah Khan
@technbuzz
Nov 07 2016 10:09 UTC
How can say that string should start from 1 and may or may not be followed by space?
Oniichan
@ProjectOU
Nov 07 2016 10:09 UTC
where :o
Ogundele Olumide
@Lumexralph
Nov 07 2016 10:10 UTC
@technbuzz use regEx
@technbuzz i think /(1)\s*/g
Samiullah Khan
@technbuzz
Nov 07 2016 10:12 UTC
okay @Lumexralph little help wither this /\^1{ ?}$/ will match start from 1 and may or may not be followed by space?
Abhisek Pattnaik
@abhisekp
Nov 07 2016 10:12 UTC
@technbuzz
/^head/.test('heading'); // true
/^head/.test('I am your head'); // false
/head/.test('who is the head of department?'); // true
/head$/.test('Your head'); // true
@technbuzz
/^head(?=\s)/.test('head of dept.'); // true
/^head(?=\s)/.test('heading is mine'); // false
Ogundele Olumide
@Lumexralph
Nov 07 2016 10:14 UTC
@technbuzz try the pattern I pasted if it'll do what you want
Samiullah Khan
@technbuzz
Nov 07 2016 10:15 UTC
@Lumexralph (1)\s* will match spaces more than one I want zero or one. I will try the @abhisekp code.
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:16 UTC
@AnnikaKW i'm stoped here
function lookUpProfile(firstName, prop){
// Only change code below this line
var i = 0;
for (i; i < contacts.length; i++) {
    if (contacts[i].hasOwnProperty(prop)) {
      console.log(contacts[i]);
      if(contacts[i]["firstName"] === firstName){
        value = contacts[i].prop;
        return value;
      } else {
        return "No such contact";
      }    
    } else {
      return "No such property";
    }
  }
// Only change code above this line
}
strangely it try only for first element
Abhisek Pattnaik
@abhisekp
Nov 07 2016 10:17 UTC
@technbuzz my code is incomplete
Check out these awesome RegEx Resources
Ogundele Olumide
@Lumexralph
Nov 07 2016 10:17 UTC
@technbuzz i used that pattern to help with an answer to your question "How can say that string should start from 1 and may or may not be followed by space?"
Samiullah Khan
@technbuzz
Nov 07 2016 10:18 UTC
Yes you are right @Lumexralph my bad I missed zero or one part
Ogundele Olumide
@Lumexralph
Nov 07 2016 10:20 UTC
@technbuzz it should be 0 or 1 followed by zero or more whitespace, right?
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:20 UTC
little question to be sure
for pomodoro exercise, user story I can reset the clock for my next pomodoro.
means you can change minutes ?
or you can stop during pomodoro ?
Philipp Scholz
@philipp32
Nov 07 2016 10:22 UTC
var Bike = function() {
    // Only change code below this line.
  var gear = 6;
  myBike.getGear=5;
  myBike.setGear=4;
};
Why aren't the setGear and getGear properties public? What am I missing?
Chandrahas P
@Chan11
Nov 07 2016 10:22 UTC
@AlexanderDom u should return 'No such property' only after searching entire array . place last return statement after for loop
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:22 UTC
@philipp32 myBike it's a Bike instance ?
Ogundele Olumide
@Lumexralph
Nov 07 2016 10:23 UTC
Am curious here...is the search and test method of a string same mechanism? asides what they return
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:23 UTC
var Bike = function() {
    // Only change code below this line.
  this.gear = 6;
  this.getGear=5;
  this.setGear=4;
};
Philipp Scholz
@philipp32
Nov 07 2016 10:24 UTC
@AlexanderDom Changed it. Still doesn't do a thing. I tried it out before. :/ It says here that "myBike.getGear() should return 3 after calling myBike.setGear(3)." doesn't work.
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:24 UTC
@Chan11 thank's it's not for me :)
CamperBot
@camperbot
Nov 07 2016 10:24 UTC
alexanderdom sends brownie points to @chan11 :sparkles: :thumbsup: :sparkles:
:cookie: 317 | @chan11 |http://www.freecodecamp.com/chan11
Philipp Scholz
@philipp32
Nov 07 2016 10:24 UTC
gear needs to be private
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:24 UTC
what's your exercice ?
Philipp Scholz
@philipp32
Nov 07 2016 10:24 UTC
var Bike = function() {
    // Only change code below this line.
  var gear = 6;
  this.getGear=5;
  this.setGear=4;
};
Doesn't work either. :/
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:24 UTC
@philipp32
Philipp Scholz
@philipp32
Nov 07 2016 10:25 UTC
Make Objects Properties Private
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:25 UTC
my pomodoro for now ;) almost there i hope https://codepen.io/AlexanderDom/pen/ALAGoo
DafyddLlyr
@DafyddLlyr
Nov 07 2016 10:27 UTC
Hi there, would anybody be able to give me a little pointer on the "Record Collection" JavaScript challenge? I feel like I'm getting pretty close to the solution (albeit a messy one maybe!), but I have one line that isn't working and I just can't figure it out. Would somebody have a minute or two to just review something for me?
Johnny
@JohnnyBizzel
Nov 07 2016 10:28 UTC
@AlexanderDom Does it work?
Abhisek Pattnaik
@abhisekp
Nov 07 2016 10:28 UTC
@philipp32 getter or setter are often functions that return the private property values
Markus Kiili
@Masd925
Nov 07 2016 10:28 UTC
@DafyddLlyr Sure.
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:28 UTC
yes it work
Abhisek Pattnaik
@abhisekp
Nov 07 2016 10:28 UTC
lol
DafyddLlyr
@DafyddLlyr
Nov 07 2016 10:28 UTC
Thanks @Masd925 . Is there any markdown I need here to post code?
CamperBot
@camperbot
Nov 07 2016 10:28 UTC
dafyddllyr sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2850 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Nov 07 2016 10:29 UTC
@DafyddLlyr There is markdown help button on low right corner there.
Chandrahas P
@Chan11
Nov 07 2016 10:29 UTC
@DafyddLlyr ctrl+shift+m
DafyddLlyr
@DafyddLlyr
Nov 07 2016 10:29 UTC
'test'
Abhisek Pattnaik
@abhisekp
Nov 07 2016 10:30 UTC
failure :x:
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:30 UTC
its ` @DafyddLlyr
Chuks Opia
@9jaswag
Nov 07 2016 10:30 UTC
hey guys. I'm on the Caesars Cipher challenge and I'm having issues with returning the right alphabet. here's my code

function rot13(str) { // LBH QVQ VG!
    sr = "";
    for (var i = 0; i < str.length; i++) {
        if (str[i] === "") {
            sr+=str[i];
        }else{
            num = str[i].charCodeAt();
            if (num > 109) {
                sr += String.fromCharCode(num-13);
            }else{
                sr += String.fromCharCode(num+13);
            }
        }
    }

  return sr;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:30 UTC
@philipp32 you don't need to set gear
DafyddLlyr
@DafyddLlyr
Nov 07 2016 10:30 UTC
test
Sorin Ruse
@sorinr
Nov 07 2016 10:30 UTC
@AlexanderDom i would give your inputs type number a min="1"
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:30 UTC
myBike.gear should remain undefined. @philipp32
@sorinr good idea ;)
DafyddLlyr
@DafyddLlyr
Nov 07 2016 10:30 UTC

`function updateRecords(id, prop, value) {

if (collection.hasOwnProperty(id) && (prop == "artist") && (value !== "")) {
collection[id][prop] = value;
} // Makes "artist" = value if ID matches & has value

else if ((collection.hasOwnProperty(id)) && (prop == "tracks") && (collection[id][prop])) {
return collection[id][prop].push(value);
} // Pushes values onto end of tracks if ID matches and tracks is present

else if ((collection.hasOwnProperty(id)) && (prop == "tracks") && (value !== "")) {
collection[id][prop] = [value];
} // Creates new tracks array with "value" in it if value is present

else if ((collection.hasOwnProperty(id)) && (value === "")) {
collection[id] = (collection[id].splice(prop));
}

return collection;
}`

Johnny
@JohnnyBizzel
Nov 07 2016 10:31 UTC
@9jaswag I think you are looking in the wrong number range!
DafyddLlyr
@DafyddLlyr
Nov 07 2016 10:31 UTC

`function updateRecords(id, prop, value) {

if (collection.hasOwnProperty(id) && (prop == "artist") && (value !== "")) {
collection[id][prop] = value;
} // Makes "artist" = value if ID matches & has value

else if ((collection.hasOwnProperty(id)) && (prop == "tracks") && (collection[id][prop])) {
return collection[id][prop].push(value);
} // Pushes values onto end of tracks if ID matches and tracks is present

else if ((collection.hasOwnProperty(id)) && (prop == "tracks") && (value !== "")) {
collection[id][prop] = [value];
} // Creates new tracks array with "value" in it if value is present

else if ((collection.hasOwnProperty(id)) && (value === "")) {
collection[id] = (collection[id].splice(prop));
}

return collection;
}

Chuks Opia
@9jaswag
Nov 07 2016 10:31 UTC
I did this cos I thought all alphabets are numbered in ascending order...turns out I was wrong
if (num > 109)
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:31 UTC
@DafyddLlyr it's three ` for many lines :)
Jan
@burning-monk
Nov 07 2016 10:31 UTC
@DafyddLlyr thre backticks + enter
Markus Kiili
@Masd925
Nov 07 2016 10:31 UTC
@DafyddLlyr You can edit your post if there is a problem.
Johnny
@JohnnyBizzel
Nov 07 2016 10:31 UTC
@DafyddLlyr carriage return between backticks
'''
CamperBot
@camperbot
Nov 07 2016 10:31 UTC
:bulb: to format code use backticks! ``` more info
DafyddLlyr
@DafyddLlyr
Nov 07 2016 10:31 UTC
ok, last time!

```function updateRecords(id, prop, value) {

if (collection.hasOwnProperty(id) && (prop == "artist") && (value !== "")) {
collection[id][prop] = value;
} // Makes "artist" = value if ID matches & has value

else if ((collection.hasOwnProperty(id)) && (prop == "tracks") && (collection[id][prop])) {
return collection[id][prop].push(value);
} // Pushes values onto end of tracks if ID matches and tracks is present

else if ((collection.hasOwnProperty(id)) && (prop == "tracks") && (value !== "")) {
collection[id][prop] = [value];
} // Creates new tracks array with "value" in it if value is present

else if ((collection.hasOwnProperty(id)) && (value === "")) {
collection[id] = (collection[id].splice(prop));
}

return collection;
}```

Jan
@burning-monk
Nov 07 2016 10:31 UTC
@9jaswag yeah there is a problem with the logic
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:31 UTC
shift enter after :)
Chuks Opia
@9jaswag
Nov 07 2016 10:31 UTC
@JohnnyBizzel I figured that out
Johnny
@JohnnyBizzel
Nov 07 2016 10:31 UTC
@DafyddLlyr carriage return between backticks
DafyddLlyr
@DafyddLlyr
Nov 07 2016 10:31 UTC
this is embarrassing! :P
Johnny
@JohnnyBizzel
Nov 07 2016 10:31 UTC
edit your entry with up arrow or click edit
Chuks Opia
@9jaswag
Nov 07 2016 10:32 UTC
@burning-monk @JohnnyBizzel how do I keep it within the range of a - z?
DafyddLlyr
@DafyddLlyr
Nov 07 2016 10:32 UTC
function updateRecords(id, prop, value) {

  if (collection.hasOwnProperty(id) && (prop == "artist") && (value !== "")) {
  collection[id][prop] = value;
  } // Makes "artist" = value if ID matches & has value

  else if ((collection.hasOwnProperty(id)) && (prop == "tracks") && (collection[id][prop])) {
  return collection[id][prop].push(value);
  } // Pushes values onto end of tracks if ID matches and tracks is present

  else if ((collection.hasOwnProperty(id)) && (prop == "tracks") && (value !== "")) {
  collection[id][prop] = [value];
  } // Creates new tracks array with "value" in it if value is present

  else if ((collection.hasOwnProperty(id)) && (value === "")) {
  collection[id] = (collection[id].splice(prop));
  }

  return collection;
}
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:32 UTC
@philipp32 look
var Bike = function() {
  this.getGear = function() {
    //your turn :)
  };
  this.setGear = function(other) {
    //your turn :)
  };
  // Only change code below this line.

};
Markus Kiili
@Masd925
Nov 07 2016 10:32 UTC
@DafyddLlyr You need to test value and prop. Property existence test is only needed when prop is tracks and value non-empty string.
Jan
@burning-monk
Nov 07 2016 10:33 UTC
@9jaswag you need a little math for that ;)
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:33 UTC
i repeat my question for pomodoro ;) for pomodoro exercise, user story I can reset the clock for my next pomodoro.
means you can change minutes ?
or you can stop during pomodoro ?
please =)
Johnny
@JohnnyBizzel
Nov 07 2016 10:34 UTC
@9jaswag Look here for the codes...http://www.w3schools.com/charsets/ref_html_ascii.asp
Stephen James
@sjames1958gm
Nov 07 2016 10:34 UTC
@9jaswag Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on.
Abhisek Pattnaik
@abhisekp
Nov 07 2016 10:34 UTC
.
Jan
@burning-monk
Nov 07 2016 10:35 UTC
@burning-monk your letters have to between 65 and 90
so if subtract 13 and it is less than 65 it is not a letter anymore
Abhisek Pattnaik
@abhisekp
Nov 07 2016 10:35 UTC
@AlexanderDom you can STOP and RESET the timer to their DEFAULT values and state.
Jan
@burning-monk
Nov 07 2016 10:35 UTC
*you
Stephen James
@sjames1958gm
Nov 07 2016 10:35 UTC
@AlexanderDom I assume you could reset the clock back to full time
DafyddLlyr
@DafyddLlyr
Nov 07 2016 10:36 UTC
@Masd925 Not sure I get that sorry. The problem I was getting was that the final line (with .splice) wasn't working and I couldn't figure out why exactly
Chuks Opia
@9jaswag
Nov 07 2016 10:37 UTC
@sjames1958gm thought of that but it'll make the code longer
Jan
@burning-monk
Nov 07 2016 10:37 UTC
@9jaswag did you see what i wrote above?
Markus Kiili
@Masd925
Nov 07 2016 10:37 UTC
@DafyddLlyr There is no need to check for existence of key id and you should not hardcode property names like "artist".
Chuks Opia
@9jaswag
Nov 07 2016 10:38 UTC
@burning-monk nope...lemme check
Alexander Domikov
@AlexanderDom
Nov 07 2016 10:39 UTC
alright, alright, alright. Thanks @sjames1958gm and @abhisekp
CamperBot
@camperbot
Nov 07 2016 10:39 UTC
alexanderdom sends brownie points to @sjames1958gm and @abhisekp :sparkles: :thumbsup: :sparkles:
:star2: 3145 | @abhisekp |http://www.freecodecamp.com/abhisekp
:star2: 4220 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Chuks Opia
@9jaswag
Nov 07 2016 10:39 UTC
@burning-monk yeah...that's what I'm about to do. thanks to the link that @JohnnyBizzel provided
CamperBot
@camperbot
Nov 07 2016 10:39 UTC
9jaswag sends brownie points to @burning-monk and @johnnybizzel :sparkles: :thumbsup: :sparkles:
:cookie: 368 | @burning-monk |http://www.freecodecamp.com/burning-monk
:cookie: 767 | @johnnybizzel |http://www.freecodecamp.com/johnnybizzel
Markus Kiili
@Masd925
Nov 07 2016 10:39 UTC
@DafyddLlyr You only need a hasOwnProperty check after you have checked that prop is tracks and value non-empty string.
Those are just redundant checks.
Stephen James
@sjames1958gm
Nov 07 2016 10:42 UTC
@9jaswag An other option is to shift the range to 0 to 25 and add 13 module 26 and then shift the range back to 65 to 90
DafyddLlyr
@DafyddLlyr
Nov 07 2016 10:43 UTC
@Masd925 Ok, that makes sense actually, just re-read the challenge description and that is correct. I will do that now and streamline the code. Do you know what is stopping the .splice line from working? Is it formatted correctly?
Chuks Opia
@9jaswag
Nov 07 2016 10:45 UTC

function rot13(str) { // LBH QVQ VG!
    sr = "";
    for (var i = 0; i < str.length; i++) {
        if (str[i] === "") {
            sr+=" ";
        }else{
            num = str[i].charCodeAt();
            if (num > 77) {
                sr += String.fromCharCode(num-13);
            }else{
                sr += String.fromCharCode(num+13);
            }
        }
    }

  return sr;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
did that and it returns FREE-CODE-CAMP. why the hyphen?
Markus Kiili
@Masd925
Nov 07 2016 10:45 UTC
@DafyddLlyr collection[id] is an (plain) object. Only arrays have splice method.
Stephen James
@sjames1958gm
Nov 07 2016 10:47 UTC
@9jaswag no value of str[i] will equal the empty string.
Jan
@burning-monk
Nov 07 2016 10:47 UTC
@sjames1958gm did you find that out by yourself?
Stephen James
@sjames1958gm
Nov 07 2016 10:47 UTC
@9jaswag space is 32 and hyphen is 45
Chuks Opia
@9jaswag
Nov 07 2016 10:48 UTC
I see
Stephen James
@sjames1958gm
Nov 07 2016 10:48 UTC
@burning-monk Find what out?
Jan
@burning-monk
Nov 07 2016 10:48 UTC
the else part is wrong
@sjames1958gm your option with modulo
Annika Williamson
@AnnikaKW
Nov 07 2016 10:49 UTC
@JohnnyBizzel I have a functioning code now. I do think it might be a bit roundabout, so I'm interested in suggestions for simplification:
Johnny
@JohnnyBizzel
Nov 07 2016 10:49 UTC
@9jaswag Glad to be of service :+1:
Stephen James
@sjames1958gm
Nov 07 2016 10:49 UTC
@burning-monk I had seen others do it.
Annika Williamson
@AnnikaKW
Nov 07 2016 10:49 UTC
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


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

  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].hasOwnProperty(prop) && contacts[i].firstName == firstName) {
      value = contacts[i][prop];
      return value;
    }
  }
  var result = "";
  var k = 0;
  while (result === "" && k < contacts.length) {
    if (!contacts[k].hasOwnProperty(prop)) {
      result = "No such property";
      return result;
    }
    else if (contacts[k].firstName !== firstName) {
      result = "No such contact";
      return result;
    }
  }
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Sherlock", "lastName");
DafyddLlyr
@DafyddLlyr
Nov 07 2016 10:49 UTC
@Masd925 Thank you, that explains why it doesn't work. Seems so simple and obvious once you realise something like that.
CamperBot
@camperbot
Nov 07 2016 10:49 UTC
dafyddllyr sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: dafyddllyr already gave masd925 points
Johnny
@JohnnyBizzel
Nov 07 2016 10:50 UTC
@AnnikaKW Ok, let me test it#
Markus Kiili
@Masd925
Nov 07 2016 10:50 UTC
@DafyddLlyr Yes, practise, practise ;)
DafyddLlyr
@DafyddLlyr
Nov 07 2016 10:50 UTC
@Masd925 I'll get back to it and see how I get on - just needed a point in the right direction. Enjoying the challenge of trying to get it worked out. Cheers!
(Y)
Jefferson
@jeffersonnnn
Nov 07 2016 10:50 UTC
Can someone tell me what an accumulator is in relation to reduce please.
Johnny
@JohnnyBizzel
Nov 07 2016 10:51 UTC
@AnnikaKW I made a fiddle. It took me a while! https://jsfiddle.net/JohnnyBizzel/xky73ga9/
Stephen James
@sjames1958gm
Nov 07 2016 10:52 UTC
@jeffersonnnn The function called by reduce returns a value, that value is passed to the next call to the function. So it can "accumlate" value as reduce operates on each value in the array.
Jan
@burning-monk
Nov 07 2016 10:52 UTC
@9jaswag if num is less than 77 and you subtract 13 it will be under 65, so you have to subtract the difference from 90
Johnny
@JohnnyBizzel
Nov 07 2016 10:52 UTC
@AnnikaKW Looking at the challenge how it is presented, the order of checking should be
  • found - return result
  • not found name - "No such contact";
  • not found property - "No such property";
    But this is not made clear.
Jan
@burning-monk
Nov 07 2016 10:53 UTC
or actually from 91
Chuks Opia
@9jaswag
Nov 07 2016 10:54 UTC
@burning-monk I dint get that
Johnny
@JohnnyBizzel
Nov 07 2016 10:55 UTC

@AnnikaKW Also, you should not create vars when you don't need...

      result = "No such contact";
      return result;

just do return "No such contact";

Annika Williamson
@AnnikaKW
Nov 07 2016 10:56 UTC
Well I'm leaning on the condition of an empty string as the value of result to keep the while loop running.
Chuks Opia
@9jaswag
Nov 07 2016 10:56 UTC

function rot13(str) { // LBH QVQ VG!
    sr = "";
    for (var i = 0; i < str.length; i++) {
        if (str[i] === " ") {
            sr+=" ";
        }else{
            num = str[i].charCodeAt();
            if (num > 77) {
                sr += String.fromCharCode(num-13);
            }else{
                sr += String.fromCharCode(num+13);
            }
        }
    }

  return sr;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
that's my code but only the first test runs @burning-monk
Johnny
@JohnnyBizzel
Nov 07 2016 10:56 UTC
@AnnikaKW Take a look at my Fiddle. You don't need a second loop.
Annika Williamson
@AnnikaKW
Nov 07 2016 10:57 UTC
Right, I like your solution. Just to get some insight on coding conventions: Is there typically one "preferred" solution to a fairly simple problem like this, or are there any number of versions that a pro would not look down on?
Ayodeji Ogundeji
@kiriyu
Nov 07 2016 10:58 UTC
blob
Jan
@burning-monk
Nov 07 2016 10:58 UTC
@9jaswag ok let's say your charcode is 77 that's an M then 77 -13 is 64 but 64 isn't between A and ` anymore, so you have to start again at 91, so you subtract from 77 only 12 and that's 65 and the rest you subtract from 91, that is 91-1=90 and 90 is Z
Johnny
@JohnnyBizzel
Nov 07 2016 10:58 UTC
@AnnikaKW There are more efficient solutions yes. Many ways to do this!
Jan
@burning-monk
Nov 07 2016 10:58 UTC
*betwenn A and Z
Annika Williamson
@AnnikaKW
Nov 07 2016 10:58 UTC
@JohnnyBizzel Thanks!
CamperBot
@camperbot
Nov 07 2016 10:58 UTC
annikakw sends brownie points to @johnnybizzel :sparkles: :thumbsup: :sparkles:
:cookie: 768 | @johnnybizzel |http://www.freecodecamp.com/johnnybizzel
Stephen James
@sjames1958gm
Nov 07 2016 10:59 UTC
@9jaswag Do not transform any non-alphabetic character (i.e. spaces, punctuation), but do pass them on.
You are only handling spaces, maybe put your alphabet check first putting all others is else
Johnny
@JohnnyBizzel
Nov 07 2016 10:59 UTC
@AnnikaKW I would not "look down on" code. If it works it works. If I can read and understand it, even better. That is the main thing. Can someone read and understand what you did!
Annika Williamson
@AnnikaKW
Nov 07 2016 11:00 UTC
:)
Johnny
@JohnnyBizzel
Nov 07 2016 11:01 UTC
@AnnikaKW Many campers go back and re-do challenges to see if they can improve them. I am doing this myself. You're knowledge improves as you go on.
Blauelf
@Blauelf
Nov 07 2016 11:01 UTC

@kiriyu No 1,2,3 in the instructions, but "a", "b", "c":

Instructions

Write a switch statement to set answer for the following conditions:
"a" - "apple"
"b" - "bird"
"c" - "cat"
default - "stuff"

Johnny
@JohnnyBizzel
Nov 07 2016 11:01 UTC
Lots of RTFM going on today :D
Annika Williamson
@AnnikaKW
Nov 07 2016 11:02 UTC
@JohnnyBizzel Yes I'm definitely still getting the JS logic into my head. Thanks for all your detailed help.
CamperBot
@camperbot
Nov 07 2016 11:02 UTC
annikakw sends brownie points to @johnnybizzel :sparkles: :thumbsup: :sparkles:
:warning: annikakw already gave johnnybizzel points
Johnny
@JohnnyBizzel
Nov 07 2016 11:02 UTC
@AnnikaKW ;)
Jan
@burning-monk
Nov 07 2016 11:03 UTC
@AnnikaKW are you german?
Annika Williamson
@AnnikaKW
Nov 07 2016 11:04 UTC
@burning-monk yes
Ayodeji Ogundeji
@kiriyu
Nov 07 2016 11:04 UTC
@Blauelf hey, thanks. how did you know?
CamperBot
@camperbot
Nov 07 2016 11:04 UTC
kiriyu sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 2815 | @blauelf |http://www.freecodecamp.com/blauelf
Chuks Opia
@9jaswag
Nov 07 2016 11:05 UTC
@burning-monk but according to the if/else if my charcode is at 77, it should add 13 not subtract
Jan
@burning-monk
Nov 07 2016 11:05 UTC
@AnnikaKW williamson doesn't sound german
Annika Williamson
@AnnikaKW
Nov 07 2016 11:06 UTC
@burning-monk Yeah well probably plenty of Americans named Díaz too.
;)
Jan
@burning-monk
Nov 07 2016 11:07 UTC
@AnnikaKW ja aber englische Namen sind im Deutschen seltener
@9jaswag if you decode an M, what shall it be?
Johnny
@JohnnyBizzel
Nov 07 2016 11:07 UTC
Burning Monk isn't much of a name!
Annika Williamson
@AnnikaKW
Nov 07 2016 11:08 UTC
@burning-monk Man kann sich ja beliebige Namen anheiraten, erben, etc.
Jan
@burning-monk
Nov 07 2016 11:08 UTC
@9jaswag do some encoding and decoding with some words on a paper
Chuks Opia
@9jaswag
Nov 07 2016 11:09 UTC
@burning-monk M = Z
Capt.PNG
Jan
@burning-monk
Nov 07 2016 11:11 UTC
@AnnikaKW schon klar, bist du zweisprachig?
Stephen James
@sjames1958gm
Nov 07 2016 11:11 UTC

@9jaswag Here is a trick I used to make the code easier to understand

var A = "A".charCodeAt(0);
var M = "M".charCodeAt(0);
var Z = "Z".charCodeAt(0);

Then no numbers are required to determine ranges

Ayodeji Ogundeji
@kiriyu
Nov 07 2016 11:12 UTC
pls, how do i attach pics of code on here?
Chuks Opia
@9jaswag
Nov 07 2016 11:12 UTC
@sjames1958gm how do I implement that?
??
Jan
@burning-monk
Nov 07 2016 11:12 UTC
@9jaswag yes and charcode of M is 77 and of Z is 90, so you need a formula that 77-13 is 90
Annika Williamson
@AnnikaKW
Nov 07 2016 11:12 UTC
@burning-monk ja
Chuks Opia
@9jaswag
Nov 07 2016 11:13 UTC
@kiriyu just drag the pic into this page and release
@burning-monk true
Stephen James
@sjames1958gm
Nov 07 2016 11:13 UTC
@9jaswag Just like that the variable A has the char code of "A", etc.
Jan
@burning-monk
Nov 07 2016 11:13 UTC
@AnnikaKW hast schon einen zum pairen?
Stephen James
@sjames1958gm
Nov 07 2016 11:13 UTC
@9jaswag Put those at the top of your function
Annika Williamson
@AnnikaKW
Nov 07 2016 11:14 UTC
@burning-monk Nein aber weiß nicht, ob ich schon so weit bin. Macht man doch erst bei den nonprofit-Projekten, oder?
Chuks Opia
@9jaswag
Nov 07 2016 11:16 UTC
@burning-monk so what's the formula?
@sjames1958gm I'll try that in a bit
Ayodeji Ogundeji
@kiriyu
Nov 07 2016 11:17 UTC
fcc1.PNG anyone know whats wrong with this code?
Ogundele Olumide
@Lumexralph
Nov 07 2016 11:17 UTC
Is there any elegant/ less code way to solving the SpinalCase challenge...? Anyone
Jan
@burning-monk
Nov 07 2016 11:17 UTC
i tested it like this if str.charCodeAt(i)-65-13 >= 0) else str.charCodeAt(i)-65 -13 + 91
Ayodeji Ogundeji
@kiriyu
Nov 07 2016 11:19 UTC
@9jaswag thanks man.
CamperBot
@camperbot
Nov 07 2016 11:19 UTC
kiriyu sends brownie points to @9jaswag :sparkles: :thumbsup: :sparkles:
:cookie: 260 | @9jaswag |http://www.freecodecamp.com/9jaswag
Stephen James
@sjames1958gm
Nov 07 2016 11:19 UTC
@kiriyu The table of values does not map numbers but letters.
"a" - "apple"
"b" - "bird"
"c" - "cat"
default - "stuff"
Chuks Opia
@9jaswag
Nov 07 2016 11:19 UTC
@burning-monk what action will the if & else run?
@kiriyu you welcome
Johnny
@JohnnyBizzel
Nov 07 2016 11:20 UTC
@9jaswag I did it like this:
if (charToTest.charCodeAt(0) < 78) { .... + 13 } else { ..... - 13 }
sort of..
Jan
@burning-monk
Nov 07 2016 11:20 UTC
function rot13(str) {
 // return 91 +"M".charCodeAt(0)-65-13;
  var newStr = [];
  //arr[0] = String.fromCharCode(str.charCodeAt(0)-13);

 for (var i = 0; i < str.length; i++) {
   if ((str.charCodeAt(i) > 64 && str.charCodeAt(i) < 91) && str.charCodeAt(i)-65-13 >= 0){
     newStr[i] = String.fromCharCode(str.charCodeAt(i)-13);
  }
   else if (str.charCodeAt(i) > 64 && str.charCodeAt(i) < 91) {
      newStr[i] = String.fromCharCode(str.charCodeAt(i)-65 -13 + 91);
   }
   else newStr[i] = str[i];
 }
  return newStr.join('');
}
rot13("SERR PBQR PNZC");
Chuks Opia
@9jaswag
Nov 07 2016 11:22 UTC
@JohnnyBizzel your solution ends up just like mine..only one test works
Ayodeji Ogundeji
@kiriyu
Nov 07 2016 11:22 UTC
@sjames1958gm I still don't undserstand.
Chuks Opia
@9jaswag
Nov 07 2016 11:22 UTC
but @burning-monk code works
Johnny
@JohnnyBizzel
Nov 07 2016 11:22 UTC
@9jaswag Full solution for you:
function rot13(str) { // LBH QVQ VG!
  var resArr = [];
  var testStr = str.split('');
  var patternAZ = /[A-Z]/;
  var result = '';
  var i = 0;
  var len = testStr.length;
  for (i = 0; i < len; i++) {      
      result = testStr[i].match(patternAZ);
      if (result === null) {
        resArr.push(testStr[i]);
      } else { 
        if (testStr[i].charCodeAt(0) < 78) { 
          resArr.push(String.fromCharCode(testStr[i].charCodeAt(0) + 13));  
        } else { 
          resArr.push(String.fromCharCode(testStr[i].charCodeAt(0) - 13));  
        }
      }

  }

  return resArr.join('');
}
Chuks Opia
@9jaswag
Nov 07 2016 11:23 UTC
@JohnnyBizzel works too...lemme study both codes
Stephen James
@sjames1958gm
Nov 07 2016 11:24 UTC
@9jaswag if you use those variables then you can have code like this without (65 or 77 or 90)
if (charCode >= A && charCode <= M)
Chuks Opia
@9jaswag
Nov 07 2016 11:25 UTC
@JohnnyBizzel you used regex :frowning: ..I knew that would work but still haven't fully wrapped my head around regex
@sjames1958gm I know...I just wanted to explore more options
Johnny
@JohnnyBizzel
Nov 07 2016 11:25 UTC
@9jaswag Useful to learn Regular Expressions!! Note I test one char at a time.
Chuks Opia
@9jaswag
Nov 07 2016 11:26 UTC
@JohnnyBizzel I know...still finding the perfect tutorial. all I've seen so far don't teach it from the basics
Stephen James
@sjames1958gm
Nov 07 2016 11:26 UTC
@9jaswag
function rot13(str) { // LBH QVQ VG!

  return str.replace(/([A-M])|([N-Z])/g, function(m, p1, p2) {
    return String.fromCharCode(m.charCodeAt(0) + (p1 ? 13 : -13)); 
  });

}
Olfa
@OlfaDH
Nov 07 2016 11:27 UTC

hellooo guys ^^
well im a bit stuck and i need some help please :)
Challenge: Record Collection:
So ive been handed this collection:
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"
}
};

I am asked to :

Write a function which takes an album's id (like 2548), a property prop (like "artist" or "tracks"), and a value (like "Addicted to Love") to modify the data in this collection.

I have been handed 4 rules. ONE of them WONT work and i don't khnow why ?
This is the rule:
If prop is "tracks" but the album doesn't have a "tracks" property, create an empty array before adding the new value to the album's corresponding property.

and here's my code for that part that wont work :
...........//code//.........
else if (prop=="tracks" && collection[id].hasOwnProperty[prop]=== false){
var array=[] ;
array.push(value);
collection[id][prop]=array;
}
....// rest of the code//...

Why it wont work plz!! :(

Stephen James
@sjames1958gm
Nov 07 2016 11:28 UTC
@OlfaDH hasOwnProperty is a function and you are using it like an array or object use ()
Chuks Opia
@9jaswag
Nov 07 2016 11:29 UTC
@JohnnyBizzel @burning-monk @sjames1958gm thanks a lot guys...let me take time to understand the code you all sent...I'm grateful
CamperBot
@camperbot
Nov 07 2016 11:29 UTC
9jaswag sends brownie points to @johnnybizzel and @burning-monk and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: 9jaswag already gave burning-monk points
:warning: 9jaswag already gave johnnybizzel points
:star2: 4221 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Johnny
@JohnnyBizzel
Nov 07 2016 11:29 UTC
@9jaswag Anytime buddy
Olfa
@OlfaDH
Nov 07 2016 11:30 UTC
@sjames1958gm Oh my God!! what's wrong with me and this kind of errors ! :p I always miss a letter or a bracket -__-
Yes thank you James ! challenge completed! ...
CamperBot
@camperbot
Nov 07 2016 11:30 UTC
olfadh sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 4222 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Nov 07 2016 11:30 UTC
@OlfaDH :+1:
Abhisek Pattnaik
@abhisekp
Nov 07 2016 11:38 UTC

@9jaswag there is another nice solution using regex and modulus operator...

function rot13(str) { // LBH QVQ VG!
  return str.replace(/[A-Z]/g, L => String.fromCharCode(65 + L.charCodeAt(0) % 26));
}

Is there any elegant/ less code way to solving the SpinalCase challenge...? Anyone

@Lumexralph

function spinalCase(str) {
  return str.split(/\s|_|(?=[A-Z])/).join('-').toLowerCase()
}
inyasshabeeb
@inyasshabeeb
Nov 07 2016 11:38 UTC
i need a help
Abhisek Pattnaik
@abhisekp
Nov 07 2016 11:39 UTC
?
just drag and drop the image or paste the link @BeckyBao
Abhisek Pattnaik
@abhisekp
Nov 07 2016 11:40 UTC
:(
Jeevan Deep
@Jeevandeep235
Nov 07 2016 11:41 UTC

@abhisekp what is the problem with the code function fearNotLetter(str) {
var numbers=str.split('').map(function(letter){
return letter.charCodeAt();
});
for(var i=0; i<numbers.length; i++){ if(numbers[i+1] - numbers[i] >1){
return String.fromCharCode(numbers[i]+1);
}
else{
return undefined;
}
}
//return str;
}

fearNotLetter("abce");

inyasshabeeb
@inyasshabeeb
Nov 07 2016 11:41 UTC

function nextInLine(arr, item) {
// Your code here

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

Jeevan Deep
@Jeevandeep235
Nov 07 2016 11:41 UTC

@BeckyBao what is the problem with the code function fearNotLetter(str) {
var numbers=str.split('').map(function(letter){
return letter.charCodeAt();
});
for(var i=0; i<numbers.length; i++){ if(numbers[i+1] - numbers[i] >1){
return String.fromCharCode(numbers[i]+1);
}
else{
return undefined;
}
}
//return str;
}

fearNotLetter("abce");

becky bao
@BeckyBao
Nov 07 2016 11:41 UTC

if(j>=0){
if(contacts[j].hasOwnProperty(prop)){
return contacts[j].prop;

}
else return "No such property";
}
else if(j == -1){
return "No such contact";
}

return contacts[j].prop;
Jeevan Deep
@Jeevandeep235
Nov 07 2016 11:42 UTC
@sjames1958gm what is the problem with th code{

function fearNotLetter(str) {
var numbers=str.split('').map(function(letter){
return letter.charCodeAt();
});
for(var i=0; i<numbers.length; i++){ if(numbers[i+1] - numbers[i] >1){
return String.fromCharCode(numbers[i]+1);
}
else{
return undefined;
}
}
//return str;
}

fearNotLetter("abce");

becky bao
@BeckyBao
Nov 07 2016 11:42 UTC
Is it can't be used like this?
Jeevan Deep
@Jeevandeep235
Nov 07 2016 11:42 UTC
@BeckyBao What is the problem with the code

function fearNotLetter(str) {
var numbers=str.split('').map(function(letter){
return letter.charCodeAt();
});
for(var i=0; i<numbers.length; i++){ if(numbers[i+1] - numbers[i] >1){
return String.fromCharCode(numbers[i]+1);
}
else{
return undefined;
}
}
//return str;
}

fearNotLetter("abce");

@BeckyBao missing letter
somebody please help me
heroiczero
@heroiczero
Nov 07 2016 11:44 UTC
@inyasshabeeb i would use the array.shift(); and array.push();
Abhisek Pattnaik
@abhisekp
Nov 07 2016 11:45 UTC
@Jeevandeep235 wow! You need not ask each one :D
Please paste your code in a nice looking style ;) :dancer:
Checkout http://forum.freecodecamp.com/t/markdown-code-formatting/18391
Stephen James
@sjames1958gm
Nov 07 2016 11:45 UTC
@Jeevandeep235 You return undefined inside the loop?
becky bao
@BeckyBao
Nov 07 2016 11:46 UTC
HOW TO drop the image
Ogundele Olumide
@Lumexralph
Nov 07 2016 11:46 UTC
@abhisekp thanks man, can you explain the modulus solution? I understand the regEx solution
CamperBot
@camperbot
Nov 07 2016 11:46 UTC
lumexralph sends brownie points to @abhisekp :sparkles: :thumbsup: :sparkles:
:star2: 3146 | @abhisekp |http://www.freecodecamp.com/abhisekp
Jeevan Deep
@Jeevandeep235
Nov 07 2016 11:47 UTC

@sjames1958gm function fearNotLetter(str) {
var numbers=str.split('').map(function(letter){
return letter.charCodeAt();
});
for(var i=0; i<numbers.length; i++){ if(numbers[i+1] - numbers[i] >1){
return String.fromCharCode(numbers[i]+1);
}
else
{
return undefined;
}
}
//return str;

}

fearNotLetter("abce");

Now what is theproblem
Vidhi patel
@VidhiPatel5151
Nov 07 2016 11:48 UTC
can any one help me out for mouse move event
Abhisek Pattnaik
@abhisekp
Nov 07 2016 11:48 UTC
@BeckyBao Using in this style contacts[j].propi.e. using dot notation can be used when the property is the same name which is written after the dot i.e. if the object had a property with the name "prop", then only you can access the prop property using dot notation.
But here, you need to access the property whose name is stored in the variable prop. For this, you need to use [] (bracket notation)
becky bao
@BeckyBao
Nov 07 2016 11:48 UTC

function lookUp(firstName, prop){
// Only change code below this line
var name=[];

var j=-1;
for(var i=0 ;i<contacts.length;i++){
name.push(contacts[i].firstName);
}

for(var z=0 ;z<name.length;z++){

if(name[z]==firstName)
{
j=z;
}
}
if(j>=0){
if(contacts[j].hasOwnProperty(prop)){
return contacts[j].prop;

}
else return "No such property";
}
else if(j == -1){
return "No such contact";
}

// Only change code above this line
}

Stephen James
@sjames1958gm
Nov 07 2016 11:50 UTC
@Jeevandeep235 You cannot return undefined until all indexes have been checked
Abhisek Pattnaik
@abhisekp
Nov 07 2016 11:50 UTC
@Lumexralph umm.... I only provided the regex soln for spinalcase. Or are you asking about rot13?
Ogundele Olumide
@Lumexralph
Nov 07 2016 11:51 UTC
@abhisekp yes, the rot13
Abhisek Pattnaik
@abhisekp
Nov 07 2016 11:55 UTC
@Lumexralph sorry! I don't remember how I solved it using modulus. :expressionless:
I'm very hungry hence not in a mood to rethink on it again now! :yum:
Will think on it and update the wiki with the explanation later.
Oniichan
@ProjectOU
Nov 07 2016 11:56 UTC
function sendlike(){
var ID = $(this.element).attr("id");
    var other_data = $('.likeajax'+ID)[0];
    alert('.likeajax'+ID);
  var fd = new FormData(other_data);
    $.ajax({
        url: 'includes/like.php',
        data: fd,
        contentType: false,
        processData: false,
        type: 'POST',
        success: function(data){
            console.log(data);
        }
    });
}
whyish not workingg :'(
Ogundele Olumide
@Lumexralph
Nov 07 2016 12:00 UTC
@abhisekp no worries man, would study it a lil
Hristo Mitsev
@iccaka
Nov 07 2016 12:00 UTC
var myStr="FirstLine \n\ \SecondLine\ \rThirdLine"; is this right
Blauelf
@Blauelf
Nov 07 2016 12:08 UTC
@iccaka Your code in backticks (`inline code` => inline code): var myStr="FirstLine \n\ \\SecondLine\\ \rThirdLine";
There is an extra \ between \n and SecondLine, and you should not have any spaces in the string.
@ProjectOU Have you checked the Javascript console (F12 or Ctrl+Shift+I on most browsers)? Is your function called at all (do you see that alert message), and does it throw some error?
Sorin Ruse
@sorinr
Nov 07 2016 12:14 UTC
@ProjectOU what is this [0]? $('.likeajax'+ID)[0];
Hristo Mitsev
@iccaka
Nov 07 2016 12:16 UTC
thank you i got it
can somebody help me with Word Blanks ?
Oniichan
@ProjectOU
Nov 07 2016 12:19 UTC
@Blauelf and @sorinr I already fixed it ;)
Sorin Ruse
@sorinr
Nov 07 2016 12:19 UTC
@ProjectOU :+1:
Vidhi patel
@VidhiPatel5151
Nov 07 2016 12:19 UTC
CAN ANOYEBODY HELP ME OUT I HAVE PROGRESS BAR THAT PROGRESSBAR I WANT MOVE TH RIGHT N LEFT SIDE WHICH EVENT CALL FOR IT
Blauelf
@Blauelf
Nov 07 2016 12:22 UTC
@VidhiPatel5151 Don't shout, shouting is rude.
Vidhi patel
@VidhiPatel5151
Nov 07 2016 12:23 UTC
i m not shouting ..dear :worried: @Blauelf
Blauelf
@Blauelf
Nov 07 2016 12:23 UTC
@iccaka For word blanks, it's important to understand the task. If you understand it, then reviewing Constructing Strings with Variables might help. And don't forget the non-word characters (e.g. space) around the words.
D O R C ¥
@Dorcy-ndg3
Nov 07 2016 12:29 UTC
hey @Blauelf i am stuck some where are you around??
Ogundele Olumide
@Lumexralph
Nov 07 2016 12:30 UTC
@Blauelf lol, not everyone understands that
Blauelf
@Blauelf
Nov 07 2016 12:30 UTC
@Lumexralph I know :/
D O R C ¥
@Dorcy-ndg3
Nov 07 2016 12:32 UTC
function destroyer(arr1,arr2,arr3) {

  var destroyed = "";
  destroyed = arr1.filter(function(val){

   return val !== arr2; 

 });
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
how can i target 3 also
i want to return arr1 without arr2 and arr3
Chuks Opia
@9jaswag
Nov 07 2016 12:35 UTC
@abhisekp your method is not only short but straight to the point. I don't think I understand it...darn complex
Markus Kiili
@Masd925
Nov 07 2016 12:35 UTC
@Dorcy-ndg3 Adding parameters to the function is called cheating. You should use the arguments object instead.
D O R C ¥
@Dorcy-ndg3
Nov 07 2016 12:36 UTC
for example
@Masd925 i knew i was cheating and it dint even workout
DafyddLlyr
@DafyddLlyr
Nov 07 2016 12:36 UTC
@Masd925 Hey there, you still around? I just got it!
function updateRecords(id, prop, value) {

  if (prop == "artist" && value !== "") {
  collection[id][prop] = value; // Updates artist
}

  else if (collection[id][prop] && value !== "") {
  collection[id][prop].push(value); // Pushes track onto end of array
}

  else if ((collection[id].hasOwnProperty(value) === false) && value !== "") {
  collection[id][prop] = [value]; // Creates new array to contain tracks
}

  else if (value === "") {
  delete collection[id][prop]; // Deletes empty field
}

  return collection;
}
Stephen James
@sjames1958gm
Nov 07 2016 12:37 UTC
@DafyddLlyr :+1:
Chuks Opia
@9jaswag
Nov 07 2016 12:37 UTC
@burning-monk went thru your code and its also quite technical and looks like sth Einstein would come up with if he wrote js :smile: I had to settle for @JohnnyBizzel 's code cos I could wrap my head around it and is similar to @sjames1958gm code
Markus Kiili
@Masd925
Nov 07 2016 12:38 UTC
@DafyddLlyr You should not hardcode any property names like artist.
Chuks Opia
@9jaswag
Nov 07 2016 12:38 UTC
@abhisekp do you mind explaining this. looks like alien code
function rot13(str) { // LBH QVQ VG!
  return str.replace(/[A-Z]/g, L => String.fromCharCode(65 + L.charCodeAt(0) % 26));
}
DafyddLlyr
@DafyddLlyr
Nov 07 2016 12:38 UTC
Feel great - taken me hours and hours to work it! Anybody have comments on the code? Is there anything unnecessary or redundant?
D O R C ¥
@Dorcy-ndg3
Nov 07 2016 12:38 UTC
@Masd925 help me with a simple example of what ur talking about
DafyddLlyr
@DafyddLlyr
Nov 07 2016 12:38 UTC
@Masd925 true - you mentioned that earlier actually, but couldn't find a workaround. I'll have another look at it now and see if I can fix it
Stephen James
@sjames1958gm
Nov 07 2016 12:39 UTC
@DafyddLlyr If you started with if (value === "") then none of the else if would need value !== ""
if (value === "") {
}
else if (prop === "tracks") { // here you know value !== "" so test is uneeded
}
Markus Kiili
@Masd925
Nov 07 2016 12:39 UTC
@DafyddLlyr The property key in prop is either "tracks" or something else.
Whether is it artist has no special meaning. It just is not tracks.
heroiczero
@heroiczero
Nov 07 2016 12:40 UTC
@Dorcy-ndg3 arguments[0] returns the array and so on so forth
Stephen James
@sjames1958gm
Nov 07 2016 12:40 UTC
@Dorcy-ndg3 Click on the arguments link - to see what arguments contains
D O R C ¥
@Dorcy-ndg3
Nov 07 2016 12:42 UTC
i know abt em its just that this code still doesnt pass
function destroyer(arr1) {

  var destroyed = "";
  destroyed = arr1.filter(function(val){

   return val === arr1[1][2]; 

 });

  return destroyed;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Markus Kiili
@Masd925
Nov 07 2016 12:43 UTC
@Dorcy-ndg3 arr1 only holds the first passed argument [1, 2, 3, 1, 2, 3]
You need to use arguments object for the rest.
D O R C ¥
@Dorcy-ndg3
Nov 07 2016 12:44 UTC
so i use 2??
Markus Kiili
@Masd925
Nov 07 2016 12:45 UTC
@Dorcy-ndg3 Use arguments[i] and arguments.length
arguements[0] is the same as arr1
DafyddLlyr
@DafyddLlyr
Nov 07 2016 12:46 UTC
So this -
else if (prop != "tracks")
is what I should be doing?
Markus Kiili
@Masd925
Nov 07 2016 12:46 UTC
@DafyddLlyr You should always use strict equality === and !==
DafyddLlyr
@DafyddLlyr
Nov 07 2016 12:46 UTC
@sjames1958gm Thank you for that - once again quite obvious once you see it, simplifies the code a lot
CamperBot
@camperbot
Nov 07 2016 12:46 UTC
dafyddllyr sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 4223 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Nov 07 2016 12:47 UTC
@DafyddLlyr :+1:
DafyddLlyr
@DafyddLlyr
Nov 07 2016 12:48 UTC
@Masd925 That was actually a typo, I was using !== in earlier versions - thanks for the reminder
CamperBot
@camperbot
Nov 07 2016 12:48 UTC
dafyddllyr sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2851 | @masd925 |http://www.freecodecamp.com/masd925
DafyddLlyr
@DafyddLlyr
Nov 07 2016 12:52 UTC
So this looks better?
function updateRecords(id, prop, value) {


  if (value === "") {
  delete collection[id][prop]; // Deletes empty field
}

  else if (prop !== "tracks") {
  collection[id][prop] = value; // Updates artist
}

  else if (collection[id][prop]) {
  collection[id][prop].push(value); // Pushes track onto end of array
}

  else if ((collection[id].hasOwnProperty(value) === false)) {
  collection[id][prop] = [value]; // Creates new array to contain tracks
}

  return collection;
}
Prakash
@PPrakashn
Nov 07 2016 12:53 UTC
hi I'm new to java script please help me how to start?
Markus Kiili
@Masd925
Nov 07 2016 12:55 UTC
@PPrakashn Learn to spell it properly: javascript ;)
Diego Mayer
@Chrono79
Nov 07 2016 12:55 UTC

@DafyddLlyr the last else if is wrong, look at what property you're checking there
I would use hasOwnProperty in this if

  else if (collection[id][prop]) {

and leave the last one as else (without if)

Markus Kiili
@Masd925
Nov 07 2016 12:56 UTC
@PPrakashn Start doing FCC javascript challenges and maybe find some tutorial or book too. MDN is good source for specific information on JS subjects.
And most of all, avoid www.w3schools.com/ javascript material.
Prakash
@PPrakashn
Nov 07 2016 13:00 UTC
sorry for the spelling mistake @Masd925
Cranio_developer
@jpmuniz
Nov 07 2016 13:02 UTC
Hello everyone, i'm João from Brazil i'm here to learn and help!
Annika Williamson
@AnnikaKW
Nov 07 2016 13:02 UTC
Hi Coders, is it correct to say that a return statement within a function acts like a break in a switch statement? i.e. does a function stop running when a return is reached?
Diego Mayer
@Chrono79
Nov 07 2016 13:03 UTC
@AnnikaKW yes, return exits your function returning some value. Note that you can have some method that uses a return sentence and it won't exit your outer function, i.e. filter, sort, and such
Annika Williamson
@AnnikaKW
Nov 07 2016 13:03 UTC
Great, thanks @Chrono79
CamperBot
@camperbot
Nov 07 2016 13:03 UTC
:star2: 2440 | @chrono79 |http://www.freecodecamp.com/chrono79
annikakw sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
Dan Couper
@DanCouper
Nov 07 2016 13:04 UTC
@AlexanderDom this is more meta I suppose, rather than specific to the exercise, but technically, you shouldn’t really be able to stop during pomodoro, that’s the point of it. If you need to stop, you’d mark that down as being unable to do whatever you were suppoed to be doing during that time period, but that time period still passes. You’d reset to zero at the start of the next pomorodo. Different ways of approaching it though; what I’m saying is not about the code really, rather what interpretation of the technique you implement.
Jasper Zion
@JasperZion
Nov 07 2016 13:06 UTC

function updateRecords(id, prop, value) {

if (!value) {
delete collection[id][prop]; // Deletes empty field
}

else if (prop !== "tracks") {
collection[id][prop] = value; // Updates artist
}

else if (collection[id][prop]) {
collection[id][prop].push(value); // Pushes track onto end of array
}

else if (!(collection[id].hasOwnProperty(value) )) {
collection[id][prop] = [value]; // Creates new array to contain tracks
}

return collection;
}

Alexander Domikov
@AlexanderDom
Nov 07 2016 13:06 UTC
thank's @DanCouper
CamperBot
@camperbot
Nov 07 2016 13:06 UTC
alexanderdom sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 348 | @dancouper |http://www.freecodecamp.com/dancouper
Marcelo Henrique
@Marcelosilva10
Nov 07 2016 13:07 UTC
hi guys
help me, should is global
CamperBot
@camperbot
Nov 07 2016 13:07 UTC
no wiki entry for: me should is global
Marcelo Henrique
@Marcelosilva10
Nov 07 2016 13:07 UTC

// Declare your variable here
var myGlobal = 10;

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

// Only change code above this line
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}

Johnny
@JohnnyBizzel
Nov 07 2016 13:08 UTC
@9jaswag I try to write readable code! Helps when I try to figure out what it does later!!
Diego Mayer
@Chrono79
Nov 07 2016 13:08 UTC
@JasperZion that's still wrong, for the same reason I said above. While it can work, conceptually the last if condition is wrong
Marcelo Henrique
@Marcelosilva10
Nov 07 2016 13:08 UTC
myGlobal should be defined
myGlobal should have a value of 10
myGlobal should be declared using the var keyword
oopsGlobal should have a value of 5
Do not declare oopsGlobal using the var keyword
Chuks Opia
@9jaswag
Nov 07 2016 13:08 UTC
@JohnnyBizzel its the best way to go
Anthony
@AverageArod
Nov 07 2016 13:10 UTC
Im stuck on testing objects for properties
Jasper Zion
@JasperZion