These are chat archives for FreeCodeCamp/Help

10th
Feb 2015
Suzanne Atkinson
@AdventureBear
Feb 10 2015 00:37 UTC
hello! I'm trying to modify a codepen, but so far feeling frustrated at not getting what I thought I understood.
my fork, with comments int he HTML & the JS
trying to 1) use a button instead of a div in the HTML. Why? Because I don't udnerstand how the div acts as a button, unless it's simply the event being listend for (click the div)
2) Tried to use jquery to listen for MY button click. Just didn't work.
When I get passed these things, I'll do more of the work I want to do with teh JS logic. I want to randomize a totally different thing than beer names, but like the logic he has laid out
thanks for any suggestions
Dominic Jones
@towwiow
Feb 10 2015 00:40 UTC
yeah, a click can be listened for like a button, you just have to id the div and fill it in or give it some sort of semblance to a button. When I went to your page, entered my first name, I got a return of Disgruntled Dominic -- is this not what it's supposed to do?
Suzanne Atkinson
@AdventureBear
Feb 10 2015 00:42 UTC
yes it is, but it's using the original code.
I'm trying to get better at coding my udnerstanding some of the changes like using jquery, or listening for a button click rather than a div click
Dominic Jones
@towwiow
Feb 10 2015 00:43 UTC
Ah, okay.
Suzanne Atkinson
@AdventureBear
Feb 10 2015 00:43 UTC
I have commented out the code I tried to add in the HTML and the JS
Dominic Jones
@towwiow
Feb 10 2015 00:44 UTC
well your button has both a class and an ID on it. I didn't think that was possible // okay to do?
Did you try taking out one or the other and seeing if your event listener picks it up?
Nathan
@terakilobyte
Feb 10 2015 00:45 UTC
possible, perfectly acceptable, and if interacting with it through javascript, encouraged
Suzanne Atkinson
@AdventureBear
Feb 10 2015 00:45 UTC
no i iddin't it just seemed like it SHOULD work.
Nathan
@terakilobyte
Feb 10 2015 00:45 UTC
a lot of people are adopting the idea of "ids for javascript, classes for css"
Suzanne Atkinson
@AdventureBear
Feb 10 2015 00:46 UTC
what is encouraged @terakilobyte , class & ID? I did both because I was unsure, but fully udnerstand that with jquery I should be able to pick up either.
hmm. that' makes some sense!
Suzanne Atkinson
@AdventureBear
Feb 10 2015 00:56 UTC
OK, I have the button working.
trying to do too many thigns at once
Suzanne Atkinson
@AdventureBear
Feb 10 2015 01:02 UTC
OOOH yes. Got my jquery event listener working.
So simple but so satisfying.
Cristián Berríos
@crisberrios
Feb 10 2015 01:10 UTC
:thumbsup:
Suzanne Atkinson
@AdventureBear
Feb 10 2015 01:11 UTC
now have it saying my OWN random works. Shortly those random words will be converted to actual workouts
Cristián Berríos
@crisberrios
Feb 10 2015 01:12 UTC
wrap it and make it a mobile app :D
Suzanne Atkinson
@AdventureBear
Feb 10 2015 01:13 UTC
how do I do that?? :)
there are a few that do that, but mine will be better
Cristián Berríos
@crisberrios
Feb 10 2015 01:15 UTC
Phonegap and other platforms, you can write android and iOS apps in js
Suzanne Atkinson
@AdventureBear
Feb 10 2015 01:15 UTC
cool good to know
yqyeoh
@yqyeoh
Feb 10 2015 10:38 UTC
function reverse(s) {
    var o = [];
  for (var i = 0, len = s.length; i <= len; i++)
    o.push(s.charAt(len - i));
  return o.join('');
}
may I know for the first loop, wouldn't it result in error since i=0; what does s.charAt(len) return?
Darryl Dixon - Piece Digital
@piecedigital
Feb 10 2015 11:18 UTC
It is pushing each character in a given string into an array, starting at the end of the string and making it's way to the beginning.
.charAt is the position of a character in a string.

so

s.charAt(len - i)

will push a character in s, the string, at the calculated position of the string. That calculated position is equal to the value of the length of the s minus i.

Darryl Dixon - Piece Digital
@piecedigital
Feb 10 2015 11:24 UTC
I hope I explained that clearly :sweat_smile:
yqyeoh
@yqyeoh
Feb 10 2015 11:39 UTC
yea i got wat u mean, but say a string has 9 characters, the last character would be s.charAt(8) instead of s.charAt(9) right?
so in the first loop of the for statement, i=0, so what would s.charAt(9-0) return?
Darryl Dixon - Piece Digital
@piecedigital
Feb 10 2015 11:41 UTC
It should return undefined.
It wouldn't mess up the string when you join it, however.
Serhii Borovskyi
@serhiicss
Feb 10 2015 12:43 UTC
Any JS gurus present?
Darryl Dixon - Piece Digital
@piecedigital
Feb 10 2015 12:43 UTC
@serhiicss I dabble here and there :D
Need some help?
Serhii Borovskyi
@serhiicss
Feb 10 2015 12:44 UTC
yes, please. just a moment, I am working on my question :)
var list = function(obj) {
  for(var prop in obj) {
    console.log(prop);
  }
Here we create a function that takes object name as argument
Question: what does exactly prop do?
Darryl Dixon - Piece Digital
@piecedigital
Feb 10 2015 12:47 UTC
Alright, so when you are calling this function the argument you are passing is an array?
Serhii Borovskyi
@serhiicss
Feb 10 2015 12:47 UTC
obj means it is going trough objects?
Objects, not array, or they count as same thing?
Ryan Malm
@Rybar
Feb 10 2015 12:48 UTC
prop represents the keys in your object.
Darryl Dixon - Piece Digital
@piecedigital
Feb 10 2015 12:48 UTC
prop is the key that iterates through the array.
Serhii Borovskyi
@serhiicss
Feb 10 2015 12:48 UTC
but how does prop know what to do if it can be anything?
Ryan Malm
@Rybar
Feb 10 2015 12:48 UTC
not necessarily an array, but all of the key:value pairs in the object you pass in.
it doesn't. It will log anything from vars to number to functions.
Serhii Borovskyi
@serhiicss
Feb 10 2015 12:49 UTC
ah
So basically it reads anything it sees in the object?
Ryan Malm
@Rybar
Feb 10 2015 12:49 UTC
reads anything enumerable, yes.
all objects have a handful of properties that aren't enumerable, and those won't get logged.
Serhii Borovskyi
@serhiicss
Feb 10 2015 12:50 UTC
So if I call the function above, it should return everything in the object (all keys and values)?
No, it only returns the object names
I think I got it. Thank you, guys!
Darryl Dixon - Piece Digital
@piecedigital
Feb 10 2015 12:55 UTC
:+1:
Ryan Malm
@Rybar
Feb 10 2015 12:55 UTC
it doesn't reach into an object. If the object passed in is an array of objects, then yes you'd just get objects in your log.
Serhii Borovskyi
@serhiicss
Feb 10 2015 12:56 UTC
In other words it only loops trough objects, but not the object keys and values.
Ugh, programming is not easy :)
Ryan Malm
@Rybar
Feb 10 2015 13:03 UTC
no it should log all of the keys
Serhii Borovskyi
@serhiicss
Feb 10 2015 13:09 UTC
Then why does it return only objects? Is it because in function(obj) we only call objects?
var friends = {};
friends.bill = {
  firstName: "Bill",
  lastName: "Gates",
  number: "(206) 555-5555",
  address: ['One Microsoft Way','Redmond','WA','98052']
};
friends.steve = {
  firstName: "Steve",
  lastName: "Jobs",
  number: "(408) 555-5555",
  address: ['1 Infinite Loop','Cupertino','CA','95014']
};

var list = function(obj) {
  for(var prop in obj) {
    console.log(prop);
  }
};
Ryan Malm
@Rybar
Feb 10 2015 13:10 UTC
so you're passing friends{} to your list function?
Serhii Borovskyi
@serhiicss
Feb 10 2015 13:10 UTC
list(friends)
bill
steve
yes
Ryan Malm
@Rybar
Feb 10 2015 13:11 UTC
ah yes, I think we just crossed wires.. so it doesn't reach into objects recursively unless you built a function that did so. if you did list(friends.steve) you'd get all of steves keys.
Serhii Borovskyi
@serhiicss
Feb 10 2015 13:15 UTC
Ok if I call list(friends.steve) it returns keys, but not their values. How do I call them both? Keys and their values.
Ryan Malm
@Rybar
Feb 10 2015 13:20 UTC
This message was deleted
console.log(prop + " : " + prop[0])
Serhii Borovskyi
@serhiicss
Feb 10 2015 13:22 UTC
@Rybar Thank you for your help!
lotbs
@LookOnTheBrightSide
Feb 10 2015 16:13 UTC
<!doctype html>
<html>
  <head>
    <link href="https://s3.amazonaws.com/codecademy-content/projects/bootstrap.min.css" rel="stylesheet" />
    <link href='https://fonts.googleapis.com/css?family=Playfair+Display:400,400italic,700italic|Oswald' rel='stylesheet' type='text/css'>
    <link href="css/main.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>
  </head>
  <body ng-app="PizzaPlanetApp">
    <div class="header">
      <h1><span>Pizza</span><span>Planet</span></h1>
    </div>

    <div class="main" ng-controller="MainController">
      <div class="container">
        <h1>Specials for {{ today | date }}</h1>

        <h2>Appetizers</h2>
        <div class="appetizers row" ng-repeat="appetizer in appetizers">
          <div class="item col-md-9">
            <h3 class="name">{{ appetizers.name }} </h3>
            <p class="description">{{ appetizers.description  }} </p>
          </div>
          <div class="price col-md-3">
            <p class="price">{{ appetizers.price | currency }} </p>
          </div>
        </div>

        <h2>Mains</h2>
        <div class="mains row" ng-repeat="main in mains">
          <div class="item col-md-9">
            <h3 class="name">{{ mains.name }} </h3>
            <p class="description">{{ mains.description  }} </p>
          </div>
          <div class="price col-md-3">
            <p class="price">{{ mains.price | currency }} </p>
          </div>
        </div>

        <h2>Extras</h2>
        <div class="extras row" ng-repeat="extra in extras">
          <div class="item col-md-9">
            <h3 class="name">{{ extras.name }} </h3>
            <p class="description">{{ extras.description }} </p>
          </div>
          <div class="price col-md-3">
            <p class="price">{{ extras.price | currency }} </p>
          </div>
        </div>

      </div>
    </div>

    <div class="footer">
    </div>

    <!-- Modules -->
    <script src="js/app.js"></script>

    <!-- Controllers -->
    <script src="js/controllers/MainController.js"></script>
  </body>
</html>
app.controller('MainController', ['$scope', function($scope) {
  $scope.today = new Date();

  $scope.appetizers = [
    {
      name: 'Caprese',
      description: 'Mozzarella, tomatoes, basil, balsmaic glaze.',
      price: 4.95
    },
    {
      name: 'Mozzarella Sticks',
      description: 'Served with marinara sauce.',
      price: 3.95
    },
    {
      name: 'Bruschetta',
      description: 'Grilled bread garlic, tomatoes, olive oil.',
      price: 4.95
    }
  ];
  $scope.mains = [
    {
      name: 'Margherita',
      description: 'Marinara sauce, mozzarella, fresh basil.',
      price: 6.95
    },
    {
      name: 'Pepperoni',
      description: 'Pepperoni, marinara sauce, mozzarella, fresh oregano.',
      price: 7.95
    },
    {
      name: 'Rustica',
      description: 'Marinara sauce, kalamata olives, roasted garlic, fresh oregano.',
      price: 8.95
    }
    ];
    $scope.extras = [
      {
        name: 'Breadsticks',
        description: 'Served with marinara  sauce',
        price: 4.95
      },
      {
        name: 'Soup of the day',
        description: 'Take a chance',
        price: 4.95
      },
      {
        name: 'Buffalo wings',
        description: 'Feel the power of wings',
        price: 6.95
      }
      ];


}]);
var app = angular.module("PizzaPlanetApp", []);
Nathan
@terakilobyte
Feb 10 2015 16:14 UTC
which isn't working, or both of them?
also
for anything in anythings
anything.something will be a property of an individual item
anythings.somethingelse will be a property of the container you're iterating over
for example look at extras
when you ng-repeat, each element should be referred to by extra, not extras
lotbs
@LookOnTheBrightSide
Feb 10 2015 16:17 UTC
mmm
ok so I can just have description?
without the mains?
{{description }}
confused
haha
Nathan
@terakilobyte
Feb 10 2015 16:19 UTC
for (main in mains) {
// I'd refer to each object in mains as main
main.property // not mains.property
}
lotbs
@LookOnTheBrightSide
Feb 10 2015 16:21 UTC
ok ill try that
thanks
Nathan
@terakilobyte
Feb 10 2015 16:21 UTC
ng-repeat essentially does this, so, first I'd try making one small change, like so
<h2>Extras</h2>
        <div class="extras row" ng-repeat="extra in extras">
          <div class="item col-md-9">
            <h3 class="name">{{ extra.name }} </h3>
            <p class="description">{{ extra.description }} </p>
          </div>
          <div class="price col-md-3">
            <p class="price">{{ extra.price | currency }} </p>
          </div>
        </div>
lotbs
@LookOnTheBrightSide
Feb 10 2015 16:21 UTC
ah
Nathan
@terakilobyte
Feb 10 2015 16:21 UTC
try that
lotbs
@LookOnTheBrightSide
Feb 10 2015 16:21 UTC
ok 2 secs
Nathan
@terakilobyte
Feb 10 2015 16:22 UTC
if extras shows up as you intended do it for the other categories
if not we'll have to dig deeper
lotbs
@LookOnTheBrightSide
Feb 10 2015 16:23 UTC
IT worked
thanks!!!!!!!!!
Nathan
@terakilobyte
Feb 10 2015 16:23 UTC
:) enjoy!
Vince
@Vince33
Feb 10 2015 21:31 UTC
How long should it take me to complete the coderbyte challenges ?
I know is relative but man they make me feel slow
Cristián Berríos
@crisberrios
Feb 10 2015 22:10 UTC
It depends
I did it in about 2 or 3 days, but I've previous coding experience
also I focused on speed rather than good practices, optimized core or code reuse
some people do it in 1 day, for others I think it can take 2 weeks or more
Anyways, use this channel if you are stuck in something
Vince
@Vince33
Feb 10 2015 22:24 UTC
cool good to know
I got hung up on one and finally skipped it and am making up ground again
Vince
@Vince33
Feb 10 2015 22:36 UTC
Does anyone know of any good resources for learning how to write test in js?
Cristián Berríos
@crisberrios
Feb 10 2015 22:38 UTC
I also want to learn TDD
I think mocha or Jasmine documentation is a good starting point
plus some grunt for running the tasks
Branden Byers
@brandenbyers
Feb 10 2015 22:39 UTC
@Vince33 If you want to start playing around with tests without setup, you can do so in the bonfire playground: http://www.freecodecamp.com/playground
It uses chaijs so you can use either assert or expect/should style: http://chaijs.com/api/
Briana Swift
@brianamarie
Feb 10 2015 22:55 UTC
Help! I think I may have myself an infinite loop or some other problem...
function DashInsert(str) { 

  var arr = str.split("");

  for (var i = 0; i<arr.length; i++){
    if (arr[i]==1||3||5||7||9){
      if (arr[i]==arr[i+1]){
        arr.splice(arr[i+1],0,"-");
      }
    }
  }
 var end = arr.join("");
return end; 

}
and/or a whole lot of problems :)
Nathan
@terakilobyte
Feb 10 2015 22:56 UTC
:)
first, use ===
don't use ==
do you know the difference?
Briana Swift
@brianamarie
Feb 10 2015 22:57 UTC
nope
Nathan
@terakilobyte
Feb 10 2015 22:57 UTC
== will implicitly type convert for you
MychaelZ
@MychaelZ
Feb 10 2015 22:57 UTC
type coercion
Nathan
@terakilobyte
Feb 10 2015 22:57 UTC
where as === will not
it is far better to be explicit
if you need to convert, do so manually
you won't be surprised later
Briana Swift
@brianamarie
Feb 10 2015 22:58 UTC
ah I see
Nathan
@terakilobyte
Feb 10 2015 22:58 UTC
in your first if, what exactly are you checking for?
if it's 1 or 3 or 5 or 7 or 9?
Briana Swift
@brianamarie
Feb 10 2015 22:59 UTC
if the number in the array (which will be all digits) is an odd number
Nathan
@terakilobyte
Feb 10 2015 22:59 UTC
or, I'm suspecting, if it's odd
Briana Swift
@brianamarie
Feb 10 2015 22:59 UTC
yep. coderbyte 23 easy
Nathan
@terakilobyte
Feb 10 2015 22:59 UTC
ok, how would I check if it was even?
Briana Swift
@brianamarie
Feb 10 2015 22:59 UTC
ah! of course! there's a method for that isn't there....
Nathan
@terakilobyte
Feb 10 2015 22:59 UTC
well, not a method that I know of unless you made one
but if (num % 2 === 0)
will return true if it's an even number
so if (num % 2 !== 0)
will be true if it's an odd
when you are nesting conditional checks you have to explicitly compare
if (num === 1 || num === 3 || num ===5)
Briana Swift
@brianamarie
Feb 10 2015 23:01 UTC
ok I see. that has screwed me up in the past, too. - I'll be back in about 15 mins, I'm sorry for post and ditching. got an important family call.
Nathan
@terakilobyte
Feb 10 2015 23:01 UTC
np
Briana Swift
@brianamarie
Feb 10 2015 23:22 UTC
function DashInsert(str) { 

  var arr = str.split("");

  for (var i = 0; i<arr.length; i++){
    if (arr[i]% 2!==0 ){
      if (arr[i]===arr[i+1]){
        arr.splice(arr[i+1],0,"-");
      }
    }
  }
 var end = arr.join("");
return end; 

}
updated
Nathan
@terakilobyte
Feb 10 2015 23:31 UTC
how is it working?
Briana Swift
@brianamarie
Feb 10 2015 23:35 UTC
not great. it's giving me a "please wait" that lasts forever
Nathan
@terakilobyte
Feb 10 2015 23:36 UTC
ah
the coderbyte blues
Cristián Berríos
@crisberrios
Feb 10 2015 23:38 UTC
@brianamarie regarding the code you posted
you are using arr[i]$ 2!==0
the values inside the array are string values
so, while it might work because of type coercion
you should make sure they are numbers first
var arr = str.split("").map(function(i) {
return +i;
});
something like that
of course, assuming your input will be a string with only digits
Briana Swift
@brianamarie
Feb 10 2015 23:43 UTC
Ah I see. The inputs should be only digits. Thank you @crisberrios!
Vince
@Vince33
Feb 10 2015 23:44 UTC
@crisberrios @brndnb Thanks guys sorry disappeared into my editor for a while
Briana Swift
@brianamarie
Feb 10 2015 23:44 UTC
I think now my main issue is the placement of the "-" in the splice. It's not exactly where I want it to be, and I'm not certain why.
Vince
@Vince33
Feb 10 2015 23:45 UTC
@brndnb I am going to dig into that bonfire and chains doc later
If I run an app locally is there any reason it wouldn't load scripts from a CDN
Cristián Berríos
@crisberrios
Feb 10 2015 23:50 UTC
@brianamarie I was assuming they were digits, what are the instructions? or can you link the challenge?
@brianamarie when you do splice, array length is modified, so the whole function gets messed
Briana Swift
@brianamarie
Feb 10 2015 23:56 UTC
Ah! I see. that makes sense! Didn't even think of that
Using the JavaScript language, have the function DashInsert(str) insert dashes ('-') between each two odd numbers in str. For example: if str is 454793 the output should be 4547-9-3. Don't count zero as an odd number.
I have a feeling I'm going to need to push something into something or...something