Complete Beginner in Coding learning javascript for node.js

547 Views Asked by At

I'm a complete newbie to coding, a complete blank slate.

I'm following the path described by: http://javascriptissexy.com/how-to-learn-javascript-properly/ to learn javascript in the build up for node.js.

It recommends that I play with code snippets from Javascript the Definitive Guide with jsfiddle or Firefox's browser console. I first tried the console and go nowhere with it but eventually found Scratchpad which would at least run code for confirm and prompt functions.

Concurrent to this, I'm working with Codeacademy where their console also returns answers and text. I can't jsfiddle or scratchpad to return non confirm/prompt function answer and I can't get the firefox browser console to do anything (where do I even write code?!?).

To test it, once more and make sure it's not just a Firefox thing, I cut and paste the firefox code into http://www.codeavengers.com/javascript/1#1.1 and it worked just like Codeacademy's console. What am I missing?

Please be detailed as I don't know up from down at this point. Thank you for your help, if you can still remember back to when you first started, I'm sure you know how much a little thing like this means! Here is an example of the code I used across codeavengers, code academy, jsfiddle and scratchpad:

confirm("Are you ready to play");

var age = prompt("What's your age");

if (age < 13) {console.log("You\'re allowed to play but we take no responsibility");} else {console.log("Let\'s get started");}

console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");

console.log("Suddenly, Beiber stops and says, 'Who wants to race me?'");

var userAnswer = prompt("Do you want to race Bieber on stage?");
if (userAnswer === "yes") {console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");} else {console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");}
var feedback = prompt("How do you rate this game on a scale of 1 to 10?");
if (feedback > 8) {console.log("Thank you! We should race at the next concert!");} else {console.log("I'll keep practicing coding and racing.");}
1

There are 1 best solutions below

1
On BEST ANSWER

In firefox, shitf+F5, click on console, click in the area at the bottom next to the blue double arrows, paste in your code (I ran your little game and it worked fine). You will need to make sure the Logging btton isn't deactivated if you want to see console.log outputs (also, sometimes they are simply ignored if they are inside a callback function).

Now, I would actually consider JavaScript (in a browser) as one of the more difficult langages (I'm using C/C++ and ASM daily so that's saying something), but it isn't as difficult when developing for node.js (though one of the big gains for using node.js for web applicatons is you can use the same code client-side as you can server-side rather than having to mix javascrpt with another language). The reason it can be tricky is browsers like to do things differently, help with optimization (though that isn't supposed to ever break your logic - it may), and are regularly updated. Also it's Object Orientation is hugely clunky and verbose. Performance can also be strange because you have a garbage collector to worry about (but don't get too concerned with that when you are starting out, loads of 'professionals' ignore the GC and don't care about performance when they are making things that are meant to be realtime).

Normally, when working with javascript in a browser you are actually maniplating web page elements (the Document Object Model, derrived from the markup [HTML] received from the web server) and some stylesheet properties. You would make functions to perform particular tasks that are run when users do something in the browser (event based).

Edit: OK so my new-ish keyboard has decded that it's going to break so may have missed some characters.