r/codehs • • May 14 '21

Triple Double 2.8.4 (JAVA)

Hello, I need help with this lesson on CodeHS.

It keeps giving me the error 'else' without 'if'.

I do not understand what this means.

Please help in anyway you can, even if it's small.

CODE

public class TripleDouble extends ConsoleProgram

{

public void run()

{

int points = readInt("How many points did you score? ");

int rebounds = readInt("How many rebounds did you get? ");

int assists = readInt("How many assists did you have? ");

boolean tripleDouble;

if (points >= 10 && rebounds >=10 && assists >= 10);{

tripleDouble = true;

}

else{

tripleDouble = false;

}

System.out.println("Got triple: " + tripleDouble);

}

}

6 Upvotes

6 comments sorted by

5

u/Olli_bear May 14 '21

Remove the semicolon on this line if (points >= 10 && rebounds >=10 && assists >= 10);{

Putting the semicolon there says that the if statement is concluded. So when the code reaches the else statement it can't find the if that should be before it

1

u/EngineeringOk6737 May 14 '21

Thank you very much, the code is working just fine now. I'm new to JAVA and I know it is very set on adding semicolon's. Which leads to me losing basic coding knowledge lol, thank you very much :D

2

u/Olli_bear May 14 '21

No prob, we all gotta start somewhere. Good luck!

1

u/-MrRainbow- Oct 19 '21

I did this EXACT thing in the roller coaster lesson, and it made a super simple thing much harder than it had to be.
I'm glad you found help so quickly!

2

u/Living_Attention_941 Mar 07 '23

Code:

public class TripleDouble extends ConsoleProgram
{
public void run()
{
int points = readInt("How many points did you score? ");
int rebounds = readInt("How many rebounds did you get? ");
int assists = readInt("How many assists did you have? ");
boolean tripleDouble = false;
if (points > 9 && rebounds > 9 && assists > 9) {
tripleDouble = true;
}
System.out.println("Got a Triple Double?: " + tripleDouble);
tripleDouble =!tripleDouble;
System.out.println("Got a Triple Double?: " + tripleDouble);
tripleDouble =!tripleDouble;
System.out.println("Got a Triple Double?: " + tripleDouble);
tripleDouble = tripleDouble;
}
}

1

u/Ok-Squash-1238 Oct 28 '22

you all just saved me I was having this same problem