Long time.. Missed you blog! Another Dice game (A real simple one) using JavaScript

Its been quite a long while since I last blogged about my learning experiences, but hey that DOES NOT mean I have stopped learning in fact I have managed to secure a job in the city of New Delhi as a Support Engineer for one of the fastest growing startups in India called Wingify Software Pvt. Ltd., check out My LinkedIn Profile for details on that.

So here comes another coding experience with Codecademy.com.

This primarily focuses on use of conditionals (if-else statements) for practice purpose of course.
This dice game has two dices, once the gamer (user) rolls the dices, depending on what the numbers they get on their dice, they get their scores.

// pick a random number between 1 and 6 for our roll of the die
var die1 = Math.floor(Math.random()*6 + 1);
var die2 = Math.floor(Math.random()*6 + 1);
var score;

// If either die roll is 1 then score should be 0 
if(die1 === 1 || die2 === 1)
    {
        score = 0;
    }
else
    {
        if (die1 === die2)
            {
                score = (die1 + die2) * 2;
            }
        else
        {
            score = die1 + die2;
        }
    }
console.log("You rolled a "+die1+" and a "+die2+" for a score of "+score);

Hopefully I will see you guys soon with more such fun and easy to create games!

Advertisements
This entry was posted in Code Academy, JavaScript and tagged , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s