Learning the Language and First Attempts
I've been using Codecademy to help me learn the basics of JavaScript, which is thankfully presented in an easy to understand and easily digestible format of many small lessons and some repetitions thrown in to cement my new knowledge. I've got lots to remember: strings, substrings, solving math, if/elses and that's just to start. My first small "game" looks like this when not in action:
// Check if the user is ready to play!
confirm("I am ready to play");
age = prompt("What's your age?");
if (age < 13){
console.log("You can play, but we take no responsibility for the content");
}
else
{
console.log("Have fun!");
}
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");
console.log("Suddenly, Bieber 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("Please rate my game out of 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.");
}
Doesn't look like too much, does it? It's basically a sort of choose your own adventure game, where what it typed into the prompts that pop up on screen change what happens next. This is word for word what the tutorial instructed, so I really doubt I would write something about Justin Beiber on my own. Take a look at it here. One thing to note about this link: console.log doesn't show up as html text on a webpage, so view it through a web browser's console, like firebug for firefox.
Remembering how to write the if/else conditions was the trickiest thing for me to remember, it all needs to be written in a specific way so that it'll work and just missing a tiny element makes the whole thing not work. Thankfully the tutorials I'm using displays all the errors so I know where I'm messing up.
I'll have to put up a link so that the code can be tried out.
On to more complicated things!
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home