さて、確認機能、プロンプト、および if - else ステートメントを使用して、Javascript を使用して小さなアマチュア ゲームを作成しています。ただし、ここで見つけることができる私のコードでは: http://jsfiddle.net/ShiiFtyyMendoza/yFzxj/15/
function codeAddress() {
if (prompt('Have you played this game?') === 'no') {
confirm('This game is like Zork!');
prompt('Do you need a refresher?');
if (prompt('Do you need a refresher?') === 'yes'); {
confirm('All it is, is that you are given a scenario, in which you are also given actions. These actions lead you through a certain path and ending. Pick carefully!');
}
} else {
confirm('Lets play then!');
}
//beginning of game
confirm('Dazed and a little groggy, you realize that you are trapped on an island after a crash landing. Along with other children, you know itd be a best idea to go and keep everybody calm.');
//stay calm.
prompt('What are you planning to do? 1. Stay calm and keep everybody in check. or 2. Panic.');
if (prompt('What are you planning to do? 1.Stay calm and keep everybody in check. or 2. Pacnic') === '1.'); { //this ends after line 19
confirm('That seems like a great idea. You go around the island, doing your best to convince others to stay calm and keep their composure.');
prompt('In the attempt to stay calm, you know that youve read about some situation like this - it was in Lord of the Flies, yes! That was it! With Piggy on your side as you walk the beach, you know you had to get an item to get peoples attention. What would you do? 1. Pick up a conch laying on the beach, or 2. Take Piggys glasses');
if (prompt('In the attempt to stay calm, you know that youve read about some situation like this - it was in Lord of the Flies, yes! That was it! With Piggy on your side as you walk the beach, you know you had to get an item to get peoples attention. What would you do? 1. Pick up a conch laying on the beach, or 2. Take Piggys glasses') === '1.'); {
confirm('Yeah, that was probably the best idea. With the conch you could blow into it and end up being able to gather attention and create a leadership.');
}
} else {
{
confirm('That works too! The sunny day lets you focus the concentrated light onto wood and create a fire.');
confirm('Soonly, as you wait, you see a helicopter from the horizon come and land. Oh what a miracle! Youve been saved!');
confirm('Or so you thought');
confirm('30 minutes into the flight, a dog fight occurs by your position, shooting your helicopter out of the sky, landing you onto another island, this time even farther than before.');
confirm('Game over.');
}
} else {
{
confirm('Ahh... this isnt so good. Your commotion had instigated chaos and getting others to follow in your stead would be extremely challenging.');
confirm('In the choice of panicing, every attempt to gather every or even anybody to keep composure, the group of boys fail to make ends meet. Slowly, as each day passes, you grow weak, only for you to realize that the choices that you had made was a catalyst of failure - causing death for others, and soon enough, you.');
}
}
}
window.onload = codeAddress;
21 行目と 29 行目にセミコロンがないため、エラーがあります。私は何を間違っていますか?私はJSの共謀をよく知らないので、かなり迷っています!どんな助けでも大歓迎です!
更新
GitaarLAB の回答に基づいて、次のコードを作成しました: http://jsfiddle.net/ShiiFtyyMendoza/yFzxj/24/
function codeAddress() {
var answer;
answer = prompt('Have you played this game?');
if (answer === 'no') {
confirm('This game is like Zork!');
answer = prompt('Do you need a refresher?')
if (answer === 'yes') {
confirm('All it is, is that you are given a scenario, ' + 'in which you are also given actions. ' + 'These actions lead you through a certain path ' + 'and ending. Pick carefully!');
}
} else {
{
confirm('Lets play then!');
}
}
//beginning of game
confirm('Dazed and a little groggy, you realize that you are ' + 'trapped on an island after a crash landing. \n' + 'Along with other children, you know it\'d be a best ' + 'idea to go and keep everybody calm.');
answer = prompt('What are you planning to do? \n' + '1. Stay calm and keep everybody in check, or \n' + '2. Panic.');
if (answer === '1') {
{
{ //stay calm
confirm('That seems like a great idea. \n' + 'You go around the island, doing your best to ' + 'convince others to stay calm and keep their composure.');
answer = prompt('In the attempt to stay calm, you know that ' + 'youve read about some situation like this - ' + 'it was in Lord of the Flies, yes! That was it! \n' + 'With Piggy on your side as you walk the beach, ' + 'you know you had to get an item to get peoples ' + 'attention. \n\n' + 'What would you do? \n' + '1. Pick up a conch laying on the beach, or \n' + '2. Take Piggys glasses');
}
if (answer === '1') {
{
{
{ //pick conch
confirm('Yeah, that was probably the best idea. \n' + 'With the conch you could blow into it and end ' + 'up being able to gather attention and create ' + 'a leadership.');
answer = prompt('With a tool to help gather attention,' + ' itd be a shame if you didnt put it to good use. \n' + ' Would you 1. try to preserve civilization on the island? \n' + ' or 2. go primitive, in an attempt to escape quickly');
if (answer === '1') { //establish leadership - to follower else
confirm('With the help of others,' + ' you were able to create multiple shelters' + '. By doing so, you were able to increase your chance of surviving.')
answer = prompt('With the comfort of having shelter, you are led into a disagreement with Jack.' + ' He, himself creates a separate group, weakining the once joint operation.' + 'you have a choice to fight back, in an attempt to be able to all go home together as one. \n' + 'What is your decision? 1. Stay calm and sleep in your newly made shelter \n' + 'or \n' + '2. Plan your escape with the others.');
if (answer === '1') { //sleep calmly
confirm('After your little disagreement, you decided to stay calm, and sleep instead of rising up and fighting.' + ' But as soon as you come out of your shelter, you realize that something is oh so very wrong.' + ' Nobody is here! Everybody else had been eloquently convinced by Jack to leave your intention for his.' + ' That worthless hunting group. He put the human primitive nature in front of priorities!');
answer = prompt('You do have a choice though. /n' + '1. Would you go lone wolf and work hard to save yourself? \n' + '2. or would you instead look for them? In the hopes of joining their league.');
if (answer === '2') //look for them
{
{
confirm('With the decision to walk around and try to find the group,' + ' you hear a chant - the hunting chant.' + ' They were close by...' + ' As you closed up, however, you were attacked by Roger and Jack.' + ' How weird. You dont remember any reason for hostility, until Sam and Eric came by.' + ' Hey! OVER HERE! said Sam and Eric \n' + ' As you came closer, their voices became fainter' + ' Run, they said. That was all they said.');
confirm('You didnt think so at first, but the twins were right.' + ' As soon as you started to run, you were spotted by Jack.' + ' With a sadistic sense, he lit the forest they had all once occupied, on fire.');
confirm('Closer and closer, you ran towards the shore,' + ' but it was a trap!' + ' There was no way out, they had lit the forest on fire to drag you out.');
confirm('Life seems to flash before you, until you realize that a ship started to aproach.' + ' Out came the navy officer, and you were finally saved.');
confirm('Good game!');
}
} else { //fire signal - from if followers are gone
confirm('You try to go lone wolf,' + ' in order to, you had created different signals to be seen.' + ' One, was a drawn message on the shore.');
confirm('Another attempt was to set fire on to the forest.');
confirm('This would have worked, however fights had not occured by your position, and you were never discovered.');
confirm('Without any materials to create signals, and the death of many animals and other sources of food,' + ' you slowly perished.');
confirm('Game over');
}
}
} else {
{ //raft from followers, if from establish leadership
confirm('You in the end decide to leave it all, and to do so, you desperately thought of an option to use as an escape.')
confirm('With the others boys, you decided a plan.')
confirm('Going through the island, looking for stable pieces of wood, you decided to build a raft.')
confirm('What a great idea! Youll be able to go home!')
confirm('At least you hoped so.')
confirm('That same day, as you hopelessly rowed away from the island, a storm hits.')
confirm('With your lack of ability to swim for long periods of time, you fatigue and slowly drown to your death.')
confirm('It would have probably been better to stay with the other boys at the island.')
confirm('Game over.')
}
}
} else { //glasses
confirm('That works too! The sunny day lets you focus ' + 'the concentrated light onto wood and create a fire.');
confirm('Soonly, as you wait, you see a helicopter from ' + 'the horizon come and land. \n' + 'Oh what a miracle! Youve been saved!');
confirm('Or so you thought');
confirm('30 minutes into the flight, a dog fight occurs ' + 'by your position, shooting your helicopter out ' + 'of the sky, landing you onto another island, ' + 'this time even farther than before.');
confirm('Game over.');
}
}
}
}
} else {
{ //panic
confirm('Ahh... this isnt so good. \n' + 'Your commotion had instigated chaos and getting ' + 'others to follow in your stead would be extremely ' + 'challenging.');
confirm('In the choice of panicing, every attempt to gather ' + 'every or even anybody to keep composure, the group ' + 'of boys fail to make ends meet. \n' + 'Slowly, as each day passes, you grow weak, only ' + 'for you to realize that the choices that you had ' + 'made was a catalyst of failure - causing death for ' + 'others, and soon enough, you.');
}
}
}
window.onload = function () {
codeAddress();
};
どう思いますか?