# Thread: What's wrong with this script?

1. Registered User
Join Date
Jun 2012
Posts
9

## What's wrong with this script?

I'm trying to make a CPU v player FizzBuzz game.
I know it's not perfectly typed, but that doesn't matter. It's loosely typed anyway.
I made a ran(para) function to make a random number from 1 to para.
Then I made a script that calculated the correct sequence.
Then a computer script with a chance to go wrong.
Then a prompt script that prompted for the numbers one by one and showed you the computer's guess one by one, also computing if you lost or drew.
I can't go on with incorrect script :P

It says "Missing ;(semicolon)". I say "?"
Code:
```var correct = new Array();
var a = 0;
var diff=prompt("What difficulty level? (Easy, Medium, Hard, Expert)");
var random;
var ran=function(para) {;
Math.floor(Math.random()*para+1);
};
var guess=new Array();
var c;
var run=1;
for (i=1; i<=20; i++) {
if (i &#37; 3 === 0) {
if (i % 5 === 0) {
correct[a] = "FizzBuzz";
}
if (i % 5 != 0) {
correct[a] = "Fizz";
}
} else {
if (i % 5 === 0) {
correct[a] = "Buzz";
} else {
correct[a] = i;
}
}
var a = a+1;
}
if (diff==="Easy") {
var random=5;
}
if (diff==="Medium") {
var random=10;
}
if (diff==="Hard") {
var random=50;
}
if (diff==="Expert") {
var random=500;
}
for (i=1; i<=100; i++) {
if (i % 3 === 0) {
if (i % 5 === 0) {
if (ran(random)===1) {
guess[a] = "Buzz";
} else {
guess[a] = "FizzBuzz";
}
}
if (i % 5 != 0) {
if (ran(random)===1) {
guess[a] = "FizzBuzz";
} else {
guess[a]="Fizz";
}
}
} else {
if (i % 5 === 0) {
if (ran(random)===1) {
guess[a] = "Fizz";
} else {
guess [a]="Buzz";
}
} else {
guess[a] = i;
}
}
var a = a+1;
}
for (b=1;b<=20;b++) {
while (run===1) {
var c=b-1;
if (guess[c]===correct[c]) {
var run=-1
} else {
var run=-1
} else {
}
}
if (run != -1) {
var run=0;
}
}
if (run != -1) {
var run=1;
}
}
}```
Last edited by Likegames; 06-13-2012 at 01:52 PM. Reason: Adding more

2. Registered User
Join Date
Nov 2010
Posts
1,276
I get a token { error here:
Code:
` alert{"You lose."}`
which is fair enough.

I get a token "else" here:
Code:
```if (guess[c]===correct[c]) {
var run=-1
} else {
var run=-1
} else {
}```
which is also fair enough - how can you have two else's?

once it starts working, the computer guess is undefined.

time for you to learn some basic debugging, me thinks

3. Registered User
Join Date
Jun 2012
Posts
9
Originally Posted by xelawho
I get a token { error here:
Code:
` alert{"You lose."}`
which is fair enough.

I get a token "else" here:
Code:
```if (guess[c]===correct[c]) {
var run=-1
} else {
var run=-1
} else {
}```
which is also fair enough - how can you have two else's?

once it starts working, the computer guess is undefined.

time for you to learn some basic debugging, me thinks
It was meant to be <if><if><else><else>
Code:
```var correct = new Array();
var a = 0;
var diff=prompt("What difficulty level? (Easy, Medium, Hard, Expert)");
var random;
var ran=function(para) {;
Math.floor(Math.random()*para+1);
};
var guess=new Array();
var c;
var run=1;
for (i=1; i<=20; i++) {
if (i &#37; 3 === 0) {
if (i % 5 === 0) {
correct[a] = "FizzBuzz";
}
if (i % 5 != 0) {
correct[a] = "Fizz";
}
} else {
if (i % 5 === 0) {
correct[a] = "Buzz";
} else {
correct[a] = i;
}
}
var a = a+1;
}
if (diff==="Easy") {
var random=5;
}
if (diff==="Medium") {
var random=10;
}
if (diff==="Hard") {
var random=50;
}
if (diff==="Expert") {
var random=500;
}
for (i=1; i<=100; i++) {
if (i % 3 === 0) {
if (i % 5 === 0) {
if (ran(random)===1) {
guess[a] = "Buzz";
} else {
guess[a] = "FizzBuzz";
}
}
if (i % 5 != 0) {
if (ran(random)===1) {
guess[a] = "FizzBuzz";
} else {
guess[a]="Fizz";
}
}
} else {
if (i % 5 === 0) {
if (ran(random)===1) {
guess[a] = "Fizz";
} else {
guess [a]="Buzz";
}
} else {
guess[a] = i;
}
}
var a = a+1;
}
for (b=1;b<=20;b++) {
while (run===1) {
var c=b-1;
if (guess[c]===correct[c]) {
var run=-1
} else {
var run=-1}
} else {
}
if (run != -1) {
var run=0;
}
}
if (run != -1) {
var run=1;
}
}
}```
Last edited by Likegames; 06-13-2012 at 04:01 PM.

4. Registered User
Join Date
Nov 2010
Posts
1,276
mismatched curly brackets

5. Registered User
Join Date
Jun 2012
Posts
9
Originally Posted by xelawho
mismatched curly brackets
Well that helps. Where?

6. Registered User
Join Date
Jun 2012
Posts
9
Bump

7. B.S. CIS, MPM, CSM
Join Date
Jan 2009
Posts
3,346
Should be:
Code:
`alert("You lose.");`

8. Registered User
Join Date
Nov 2010
Posts
1,276
Originally Posted by Likegames
Well that helps. Where?
the error console tells you where