These are chat archives for FreeCodeCamp/HelpJavaScript

1st
Jan 2018
Ayush Bahuguna
@relentless-coder
Jan 01 2018 06:40
Need some help here:
    const verifyEmail = (data) => {
      console.log("data is ", data);
        if (data && (data.split(':')[0]) === id) {
            console.log("data is ", data);
            branch = data.split(':')[2];
            password = getRandomInt(100000, 999999);
            role = data.split(':')[1];
            let hashPass = Person.generateHash(password);
            let data = {email, _id: id, password: hashPass, role, company}
            return Person.create(data)
        } else {
            throw new ErrorRes(404, 'Invalid email/id')
        }
    };
before the if statement, data holds a value, but then I get cannot read property 'split' of undefined and the second console.log also prints undefined
Pieter Stokkink
@forkerino
Jan 01 2018 08:24
Happy new year to all! :confetti_ball: :fireworks:
RecodeExistence
@RecodeExistence
Jan 01 2018 08:26
Happy new year to everyone too.
oops. i thought tha twould auto format.
Working on "counting cards" , and i think i'm close but perhaps my logic is a little off. any guidance would be much appreciated, thanks.
var count = 0;

function cc(card) {
  // Only change code below this line
 switch(card) {
     case(card > 1 || card < 7):
     count = count++;
     break;

     case(card > 6 || card < 10):
     break;

   default: 
     count--;
 } 

  return count > 0 ? count + " Bet" : count + " 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');
ahh there we go.
Pieter Stokkink
@forkerino
Jan 01 2018 08:30
@relentless-coder No idea, haven't slept in 28 hours, but my first step would be to differentiate the log statements.
RecodeExistence
@RecodeExistence
Jan 01 2018 08:34
hmm. i got it to work, but not in the way i'd like to. bah.
Pieter Stokkink
@forkerino
Jan 01 2018 08:36
@RecodeExistence shouldn't those ors be ands ?
RecodeExistence
@RecodeExistence
Jan 01 2018 08:38
possibly. i think there was something in my head why i used or instead. something about left hand operators returning true for and. ach, confusing myself here lol
i got it working with
case 7: case 8: case: 9
but i'd definitely prefer the logical expression for concise writing.
Pieter Stokkink
@forkerino
Jan 01 2018 09:18
@RecodeExistence a low number of different cases and quite some logic to determine which case to use, usually suggests that an if/else if/else is better.
Than a switch, I mean
RecodeExistence
@RecodeExistence
Jan 01 2018 10:00
@forkerino you're right. there are hacky ways of making the way i wanted it to work. but, this is one of those cases where accepting if/else statements are just the way to go.
Markus Kiili
@Masd925
Jan 01 2018 10:09
@RecodeExistence Using an (lookup) object is also a fine way here.
In a real card counting software it would be the way to go, because it would be easy to store and change different counting systems:
function cc(card) {
  var VALUES = {2:1,3:1,4:1,5:1,6:1,7:0,8:0,9:0,10:-1,J:-1,Q:-1,K:-1,A:-1};
  count += VALUES[card];
  return String(count) + (count>0 ? " Bet" : " Hold");
}
RecodeExistence
@RecodeExistence
Jan 01 2018 12:18
not a bad idea @Masd925 . I've learned of objects but haven't actually put them into use in building things yet so my head doesn't even think of using them for things yet heh xD
RecodeExistence
@RecodeExistence
Jan 01 2018 13:47
i guess
Math.floor(Math.random() * (max - min + 1)) + min is one of those things that's going to be useful just to have noted somewhere? xD
Christopher
@bradley1492
Jan 01 2018 14:16
@sjames1958gm Thanks for the regex tip :)
CamperBot
@camperbot
Jan 01 2018 14:16
bradley1492 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8813 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Christopher
@bradley1492
Jan 01 2018 14:31
I am still at the https://www.freecodecamp.org/challenges/validate-us-telephone-numbers challenge and I wrote out the following regex. But I still can't solve the challenge. I don't know why because to me the regex seems as precise as it gets...
https://regex101.com/r/7poaI1/5
Christopher
@bradley1492
Jan 01 2018 14:37
Or why does /1?\s?-?(\d{3})|((\d{3}))\s?-?\d{3}\s?-?\d{4}/g not match
555 555 5555?
Aditya
@ezioda004
Jan 01 2018 14:46
@bradley1492 You're also missing matches for ( ). Some cases have only one of parentheses or just at wrong position so you gotta look out for those too.
Christopher
@bradley1492
Jan 01 2018 15:02

@ezioda004 The above regex is wrong the following one is the one I intended. Like so:

1?\s?\-?(\d{3})|(\(\d{3}\))\s?\-?\d{3}\s?\-?\d{4}

But here with (\(\d{3}\))I have got the ()covered haven't I?

Why can't the regex match the last number in this one? -->
https://regex101.com/r/7poaI1/6

RecodeExistence
@RecodeExistence
Jan 01 2018 15:04
I wonder if anyone could confirm my understanding (commented), for Private Object Properties please?
var Bike = function() {

  // Only change code below this line.
  var gear;   // private variable 

  this.setGear = function(chosenGearNumber) {  // public method
    gear = chosenGearNumber;  //Pass chosenGearNumber into our private variable. 
  };
  this.getGear = function(){  // public method
     return gear;  /* allows us to return gear, after it has been set by the public setGear method */
  };

};
Ken Haduch
@khaduch
Jan 01 2018 16:00
@RecodeExistence - your comments look good.
Ken Haduch
@khaduch
Jan 01 2018 16:39
@bradley1492 - try putting parentheses around your two groups that match the 3 digit area code - (\d{3})|(\(\d{3}\)) should be ((\d{3})|(\(\d{3}\))) because you want to have either one or the other of that combination to match, but not both.
RecodeExistence
@RecodeExistence
Jan 01 2018 16:41
@khaduch thank you. I felt like I was grasping a little at what the lesson was trying to teach; And it seems like understanding objects is going to be pretty important.
CamperBot
@camperbot
Jan 01 2018 16:41
recodeexistence sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3638 | @khaduch |http://www.freecodecamp.org/khaduch
Tiago Correia
@tiagocorreiaalmeida
Jan 01 2018 19:10
hello everyone
let res = [];
let count = 0;
function prefill(n, v) {
  if(count === 0 && n === 0) return [];
  if( n < 0 || typeof n !=="number" || !Number.isInteger(n)) throw new TypeError(`${n} is invalid`);
  if(n === 0){
    let temp = [...res];
    res = [];
    return temp;
  }
  res.push(v);
  count++;
  return prefill(n-1,v);
}
any idea why this thing is trhowing me an error in one of the tests ?:\
Tiago Correia
@tiagocorreiaalmeida
Jan 01 2018 19:26
found out they send numbers as a strings and expect me to return an array empty like if it was a number :')
alpox
@alpox
Jan 01 2018 19:43
@tiagocorreiaalmeida prefill("1", 1) the "1" should probably be interpreted as number
Tiago Correia
@tiagocorreiaalmeida
Jan 01 2018 19:43
yeah
im having some other issue
only missing that thing one give it a lok ?:D
look
let res = [];
let count = 0;
function prefill(n, v) {
console.log(typeof n);
  if(count === 0 && n == 0) return [];
  if( n < 0 || typeof n !=="number" || !Number.isInteger(n)) throw new TypeError(`${n} is invalid`);
  if(n === 0){
    let temp = [...res];
    res = [];
    count = 0;
    return temp;
  }
  res.push(v);
  count++;
  return prefill(n-1,v);
}
the only test that I fail is that if the type is boolean and the value is false
not sure why if I check for the type on the throw error
"prefill did not throw an error with n as false"
Ken Haduch
@khaduch
Jan 01 2018 19:49
@bradley1492 - if you make the change that I mentioned above: :point_up: January 1, 2018 11:39 AM and then anchor your expression to the beginning and ending of the line, you should be good...
Tiago Correia
@tiagocorreiaalmeida
Jan 01 2018 20:36
got it
let res = [];
let count = 0;
function prefill(n, v) {
  if(count === 0 && n == 0 && typeof n !== "boolean") return [];
  if( n < 0 || typeof n !=="number" || !Number.isInteger(n)) throw new TypeError(`${n} is invalid`);
  if(n === 0){
    let temp = [...res];
    res = [];
    count = 0;
    return temp;
  }
  res.push(v);
  count++;
  return prefill(n-1,v);
}
tricky one