Closed stevekinney closed 9 years ago
I'm really, really not good at reading tech books, apparently.
Also, are the examples in this supposed to actually run on their own in Node? I tried typing one out and the console complained at me immediately about an unexpected token (
Code sample?
On Fri, Feb 6, 2015 at 9:45 PM, Viki Harrod notifications@github.com wrote:
Also, are the examples in this supposed to actually run on their own in Node? I tried typing one out and the console complained at me immediately about an unexpected token (
Reply to this email directly or view it on GitHub: https://github.com/turingschool/intermission-assignments/issues/5#issuecomment-73349767
function (d) { var calc = function (diameter) { var Pi = 3.14159265;
return diameter * Pi };
return "The circumference is " + calc(d) }
Thing yelled at me before I could get past line 1 though...
Are you typing this in the REPL or running a file?
On Fri, Feb 6, 2015 at 9:55 PM, Viki Harrod notifications@github.com wrote:
Thing yelled at me before I could get past line 1 though...
Reply to this email directly or view it on GitHub: https://github.com/turingschool/intermission-assignments/issues/5#issuecomment-73350119
I tried both.
Also, ignore that that sample is from maaaaybe 25% through the book >_<
It looks like the issue is just that code is out of context of a runnable script. The JavaScript engine doesn't like that there is a lonely anonymous function just hanging out in the world. So, it sounds the alarms.
If you were to do something like this, it would work:
var calculateDiameter = function (d) {
var calc = function (diameter) {
var Pi = 3.14159265;
return diameter * Pi
};
return "The circumference is " + calc(d)
}
The interpreter then sees you want to store it in a variable and is like—oh yea, totally legit.
Alternatively, you can use it as an IIFE:
(function (d) {
var calc = function (diameter) {
var Pi = 3.14159265;
return diameter * Pi
};
return "The circumference is " + calc(d)
})(20)
Huh. Weird. I guess that makes sense. I guess I was just figuring if it's in the book, it's runnable as-is.
Semi off-topic, how do you read a tech book? Do you try to just... read it? Or do you try typing out the examples even though the result's given in the book? Or something else? And does your strategy vary depending on whether it's a paper book or an e-book? I'm just finding it very difficult to stay focused on it.
I tend to—in my first pass—just read through the book and get a sense of the big picture. I liberally highlight and bookmark pages that I don't fully understand and return to them after I've gotten to the end of the book.
Read JavaScript Allongé by Reginald Braithwaite
Discuss questions and thoughts here. Feel free to talk about the book as you're reading it. I'll also answer any questions you have.
Some things to think about: