JavaScript | 자바스크립트 | INTRODUCTION TO JAVASCRIPT 여섯
JavaScript | 자바스크립트 | INTRODUCTION TO JAVASCRIPT 여섯
Choose Your Own Adventure! | Codecademy
Six. Program your first game!
File1 _ script.js
confirm("I am ready to play!");
2/7 Old enough to play?
File1 _ script.js
confirm("I am ready to play!");
var age = prompt("How old are you?");
if(age < 13) {
console.log("No No No");
} else {
console.log("Good Luck");
}
3/7 Adding some story
File1 _ script.js
confirm("I am ready to play!");
var age = prompt("How old are you?");
if(age < 13) {
console.log("No No No");
} else {
console.log("Good Luck");
}
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");
4/7 First move!
File1 _ script.js
confirm("I am ready to play!");
var age = prompt("How old are you?");
if(age < 13) {
console.log("No No No");
} else {
console.log("Good Luck");
}
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?");
5/7 The story heats up!
File1 _ script.js
confirm("I am ready to play!");var age = prompt("How old are you?");
if(age < 13) {
console.log("No No No");
} else {
console.log("Good Luck");
}
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.'");
}
| Remember: = is for assignment, and === is to check if things are equal!
6/7 Asking for feedback
File1 _ script.js
confirm("I am ready to play!");
var age = prompt("How old are you?");
if(age < 13) {
console.log("No No No");
} else {
console.log("Good Luck");
}
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("You like this?");
if (feedback > "8") {
console.log("Thank you! We should race at the next concert!");
} else {
console.log("I'll keep practicing coding and racing.");
}
7/7 Next steps!
File1 _ script.js
| 예전에 작성한 코드
confirm("I am ready to play!");
var age = prompt("What's your age?");
if(age > 18) {
console.log("Good!");
} else {
console.log("Not Good!");
}
var intro = "Snow White and Batman were hanging out at " +
"the bus stop, waiting to go to the shops. There " +
"was a sale on and both needed some new " +
"threads. You've never really liked Batman. You " +
"walk up to him.";
console.log(intro);
console.log("Batman glares at you.");
var userAnswer = prompt("Are you feeling lucky, punk?");
var yes = "yes";
var no = "no";
if(userAnswer = yes) {
console.log("Batman hits you very hard.");
console.log("It's Batman and you're you!");
console.log("Of course Batman wins!");
} else {
console.log("You did not say yes to feeling lucky.");
console.log("Good choice!");
console.log("You are a winner in the game of not getting beaten up by Batman.");
}
var feedback = prompt("Rate my game out of 10.");
if(feedback > 8) {
console.log("This is just the beginning of my game empire. Stay tuned for more!");
} else {
console.log("I slaved away at this game and you gave me that score?! The nerve! Just you wait!");
}
Next Course: Introduction to Functions in JS
| "Everybody in this country should learn how to program a computer... because it teaches you how to think."
- Steve Jobs
