Discuss Scratch

RandomPerson1789
Scratcher
100+ posts

Script not working

My script is not working (its html)
It is supposed to be a quiz game.
Here it is:
<html>
<head>
<script>
score = 0
alert(“Welcome to the quiz!”);
answer = prompt(“What is 1+1?”);
if answer==2 {
function cor();
} else {
alert(“Wrong!”);
}
answer = prompt(“What is 4X6?”);
if answer==24 {
function cor();
} else {
alert(“Wrong!”);
}
alert(“You got”, score, “out of 2 correct.”);
function cor() {
score = score + 1;
alert(“Correct!”);
}
</script>
</head>
</html>
Plz help
wkelly42
Scratcher
100+ posts

Script not working

This is a forum for help with Scratch scripting ;-)


My Retro Arcade:
COMPLETED: Frogger, Missile Command, Computer Space.
IN DEVELOPMENT: Barnstorming, Time Pilot, Defender, River Raid, Karateka
MegaApuTurkUltra
Scratcher
1000+ posts

Script not working

This goes in advanced topics. Help with scripts is for Scratch script help.

$(".box-head")[0].textContent = "committing AT crimes since $whenever"
djdolphin
Scratcher
1000+ posts

Script not working

Try this:
<html>
<head>
<script>
score = 0
alert("Welcome to the quiz!");
answer = prompt("What is 1+1?");
if (answer==2) {
cor();
} else {
alert("Wrong!");
}
answer = prompt("What is 4X6?");
if (answer==24) {
cor();
} else {
alert("Wrong!");
}
alert("You got " + score + " out of 2 correct.");
function cor() {
score = score + 1;
alert("Correct!");
}
</script>
</head>
</html>
You were using typographer's quotes (the curly ones) instead of straight ones, and you don't need to put “function” when you're calling a function - only when you're defining one. Also, use “+” to join strings, not commas.

!
goldfish678
Scratcher
1000+ posts

Script not working


<html>
<head>
<script>
var score = 0
alert("Welcome to the quiz!");
answer = prompt("What is 1+1?");
if (answer==2) {
cor();
} else {
alert("Wrong!");
}
answer = prompt("What is 4X6?");
if (answer==24) {
cor();
} else {
alert("Wrong!");
}
alert("You got " + score + " out of 2 correct.");
var cor = function() {
score = score + 1;
alert("Correct!");
}
</script>
</head>
</html>
This is djdolphin's, but improved.
MegaApuTurkUltra
Scratcher
1000+ posts

Script not working

goldfish678 wrote:

<html>
<head>
<script>
var score = 0
alert("Welcome to the quiz!");
answer = prompt("What is 1+1?");
if (answer==2) {
cor();
} else {
nope();
}
answer = prompt("What is 4X6?");
if (answer==24) {
cor();
} else {
nope();
}
alert("You got " + score + " out of 2 correct.");
var cor = function() {
score++;
alert("Correct!");
}
var nope = function(){
alert("Wrong!");
}
</script>
</head>
</html>
This is djdolphin's, but improved.
Improved a bit more. Also, I did report the OP to be moved to Advanced Topics a while ago. Where's the ST? sorry I can't read. I fell kind of stupid now

Last edited by MegaApuTurkUltra (Sept. 7, 2014 00:53:57)


$(".box-head")[0].textContent = "committing AT crimes since $whenever"
RandomPerson1789
Scratcher
100+ posts

Script not working

djdolphin wrote:

Try this:
<html>
<head>
<script>
score = 0
alert("Welcome to the quiz!");
answer = prompt("What is 1+1?");
if (answer==2) {
cor();
} else {
alert("Wrong!");
}
answer = prompt("What is 4X6?");
if (answer==24) {
cor();
} else {
alert("Wrong!");
}
alert("You got " + score + " out of 2 correct.");
function cor() {
score = score + 1;
alert("Correct!");
}
</script>
</head>
</html>
You were using typographer's quotes (the curly ones) instead of straight ones, and you don't need to put “function” when you're calling a function - only when you're defining one. Also, use “+” to join strings, not commas.
Thanks! Helped a lot

Powered by DjangoBB