我一直在做一些基本的js,但我不確定我是否正確使用分號。 這裏是我的代碼: 我在js中使用分號嗎?
//creates a variable that will start the game
var start = confirm("Are you sure want to participate in plonker base alpha?");
//starts and loops the game
if(start){
//asks for another person's name
var person1 = prompt("Please name one of your best friends.")
}
//creates a randomizer function
var random = function (subject){
return subject[Math.floor(subject.length * Math.random())]
}
while(start){
//creates array 'person'
var person = ["You are ","Your mum is ","Your dad is ", "The world is ",(person1 + " is ")];
var personGenerator = random(person);
//creates an array 'offence'
var offence = ["an idiot!",
"a complete pysco!!!",
"a smelly, worthless peice of junk!",
"a whale re-incarnated that looks like a squirrel!",
"a dumb pile of dirt that has the misfortune of seeing itself in the mirror once in a while!",
"a complete and utter plonker!",
"a dumbo!",
"a right dufus!!!",
"a pile of rabbit dung!",
"an intelligant, good looking king being... Did I mention - it's opposite day!",
"a bum-faced rat!!!",
"a fat, lazy oaf!",
"a blobfish look-alike!!!!!",
"a lump of toenail jelly!"];
var offenceGenerator = random(offence);
//gives out the offence
alert(personGenerator + offenceGenerator);
}
{
alert("What a plonker!")
}
如果我使用他們錯了請糾正我的意見。
感謝, 里斯C.
主要問題似乎是縮進,而不是分號......無論如何,你可能想問一下[codereview.se]。 – JJJ 2015-03-08 22:15:28
如果您使用的是「錯誤」,那意味着您會在某個地方出現語法錯誤。你做? – usr2564301 2015-03-08 22:15:45
每個語句都應該以分號結束,但是你通常可以避開它,因爲瀏覽器可以很好地猜測語句在哪裏結束。通過http://jslint.com運行你的代碼,這將給出一個錯誤,警告和不良實踐的列表。 – 2015-03-08 22:17:11