Get your lucky numbers with Angular

This snippet is based on the JavaScript exercise published on my eBook
“Small Projects to Learn JavaScript – Drawing Six ‘Lucky’ Numbers”

AngularJS was not even mentioned on the project but I figured it was time to demonstrate a way to implement AngularJS since it is the most popular implementation wanted right now.

Here it is: JSPLAIN

Have fun!


JavaScript Objects Functions and Arrays Explained

How many times have you attempted to learn JavaScript, only to put it on the side because it was too complex or you felt overwhelmed by the information overload?

JavaScript Objects Functions and Arrays Explained is easy to understand with plenty of illustrations and links to code files you can physically copy. Easy does not mean simple, it will not insult your intelligence and capacity to learn new concepts. This is a serious book for those wanting to understand how JavaScript works.

This book can be used as a reference if you need a detailed explanation on how a certain method works.
The key to master JavaScript is to become familiar with its library methods.

Get it today and start learning. You don’t need to own a Kindle. You’ll be able to read it on anyone of your computers by downloading the free Kindle app.
–> JavaScript Objects Functions and Arrays Explained


Fahrenheit to Celsius – JavaScript and AngularJS

You probably know how to convert Fahrenheit to Celsius in JavaScript but how would you display it on a web page?

Google has come up with a modern solution: AngularJS

AngularJS is a way to make your HTML more dynamic and it is easy to implement.

Take a look at my sample here:

Have fun testing it!

JavaScript value and reference variables

Are you still puzzled by JavaScript terms such as typeof,
reference variables, value variables, stack vs heap?
My new article at JSPLAIN (JavaScript in Plain Language)
is short, sweet and right to the point.
Here’s my link:
Have a great weekend!!

Get your six lucky numbers with AngularJS

Hi dear reader,
If you have read my eBook Small Projects to Learn JavaScript – Drawing Six ‘Lucky’ Numbers
you’ll be pleased to know that I have converted the project into AngularJS.

AngularJS was not even mentioned in the book but I figured it was time to demonstrate a way of implementing AngularJS on the script and it is a cool implementation as you may see on the following link:

Happy coding!


JavaScript’s Conditional Operator

The conditional operator is a one liner if/else statement. Another name for it is ternary operator because it uses three operands:

expression1 ? expression2 : expression3;

If expression1 evaluates to boolean true, expression2 gets executed. Else, expression3 gets executed instead.

If you’re like me, you probably prefer to use if, else if, else statements, but the ternary operator can be very handy at times. One of the things we can’t do with our regular branching techniques is to include alternative outputs on a one console.log statement, but with the ternary operator we can:

var x = 10;
var y = 9;
console.log(x < y ? "hello!" : "goodbye!");
// it outputs "goodbye!"
console.log(x > y ? "hello!" : "goodbye!");
// it outputs "hello!"

Cool thing!

White space in JavaScript

JavaScript does not care for white space. It just ignores it. However there is one exception to the rule: when the white space is in between quotes such as a string literal. Example:

var text = "the quick
brown fox
jumps over
the lazy dog";

If you test the above script on the Chrome’s Console (CTRL SHIFT j), JavaScript will throw an error: SyntaxError: Unexpected token ILLEGAL. We need to use the backslash \ as an escape character. An escape character is one which invokes an alternative interpretation on subsequent characters in a character sequence. In this case, the backslash will tell JavaScript to ignore the subsequent line break and just make it a continuous string:

var text = "the quick \
brown fox \
jumps over \
the lazy dog";

Notice how I included the space before the backslash and not after it. We only want to escape the line return. Now, when we call variable text it outputs the the correct sentence: “the quick brown fox jumps over the lazy dog