These are chat archives for FreeCodeCamp/HelpJavaScript

20th
Jan 2019
Pagnito
@Pagnito
Jan 20 00:36
hey what do u guys think about using mongodb native driver over mongoose?
nvm i read about it lol
Chinmay Joshi
@dienigma
Jan 20 02:55
So I am on this challenge. Basic Data Structures: Iterate Through the Keys of an Object with a for...in Statement.
My Code -
let users = {
  Alan: {
    age: 27,
    online: false
  },
  Jeff: {
    age: 32,
    online: true
  },
  Sarah: {
    age: 48,
    online: false
  },
  Ryan: {
    age: 19,
    online: true
  }
};

function countOnline(obj) {
  // change code below this line
  let count = 0;
  for (let user in users){
    if(user.online){
      count++;
    }
  }
  return count;
  // change code above this line
}

console.log(countOnline(users));
This should return the count of users that are online. It is not working
There is no error but its just not returning the count.
This returns 0
Christopher McCormack
@cmccormack
Jan 20 03:07
@dienigma it's only going to give you the property name as a string, not the object, you still need to access the value from the users object using users[user]
you could see that quickly by logging user on the top line of your for loop
Chinmay Joshi
@dienigma
Jan 20 03:18
@cmccormack Okay. Cool
Thanks
Chinmay Joshi
@dienigma
Jan 20 03:25
@cmccormack I need to access the online property
like users.user.online
How do I check for it?
Chinmay Joshi
@dienigma
Jan 20 03:36
Got it. Fixed it.
Keggatron
@Keggatron
Jan 20 04:08
Anyone have any experience with formik?
Prajwal Bhatia
@prajwalbhatia
Jan 20 10:44
I have learn the javascript and done some project but I am not getting comfortable with javascript please help me as I want to be a MEAN STACK developer
Riadh
@KWFE
Jan 20 13:54
@prajwalbhatia just contact me we can learn together
sanolumpen
@sanolumpen
Jan 20 20:32
hi! i'm stucked in the "Return Early Pattern for Functions" lesson, i can't do the "numbers" thing, i try in very differents ways.
Christopher McCormack
@cmccormack
Jan 20 20:55
@sanolumpen can you share what you tried and what isn't working?
sanolumpen
@sanolumpen
Jan 20 21:32

@cmccormack yes, of course, // Setup
function abTest(a, b) {
// Only change code below this line
console.log(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(2,2);

and don't complete the rest of hints
*abTest(2,2) should return a number
Jason Luboff
@JLuboff
Jan 20 21:33
You’re returning undefined, you need to return a number
sanolumpen
@sanolumpen
Jan 20 21:34
but when i type return number tells me i don't define it
Jason Luboff
@JLuboff
Jan 20 21:35
You need to return ‘a’ number not ‘number’
I don’t know the exact challenge but I imagine you need to return either a or b
sanolumpen
@sanolumpen
Jan 20 21:36
emm how i can syntax that? xD i'm trying different but i can't
console.log(a < 0 || b < 0);
return undefined
console.log(a + b)
return a, b
this are the hints:
abTest(2,2) should return a number
abTest(2,2) should return 8
Passed
abTest(-2,2) should return undefined
Passed
abTest(2,-2) should return undefined
abTest(2,8) should return 18
abTest(3,3) should return 12
whit the other syntax, marks me right the first hint.
Jason Luboff
@JLuboff
Jan 20 21:44
You need to have an if statement. If a or b is less than 0, than return undefined else it’ll return the expression below (the area you’re not supposed to edit)
sanolumpen
@sanolumpen
Jan 20 21:44
ahhh, i'm trying right now...
ready!!! thx! very much! i understand all now!!
:D