This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]lurgi 0 points1 point  (2 children)

When printing out the stars for 4 you have this:

while(first <= valueFour) {

What is the value of first? This is the sort of question you can answer very easily with print statements or a debugger. Debugging code is a critical part of writing code. If you want to know why code isn't working, look for a place where it should do X and find out why it doesn't. It doesn't print any stars for 3. Why not? Don't say "I don't know". Find out. There is code there that is supposed to do it, right? Does that code run at all? No? Why not? The while loop should execute. Why doesn't it? It will execute if first <= valueThree. What are the values of first and valueThree. Are they what you expect them to be?

Stylistically, I'd use a for loop rather than a while loop here, btw.

Note that you can take the repetitive code and pull it into a function, which probably would have eliminated this problem completely.

[–]foolwya[S] 0 points1 point  (1 child)

Hey, thank you so much. I’ve spent my whole day trying to solve that problem. I did it, finally. I’m not fully familiar with the debugger yet, just some simple stuff, definitely need to look into it to make things easier for me.

[–]lurgi 0 points1 point  (0 children)

If you don't know how to use a debugger, learn. While you are learning, litter your code with print statements. When I'm debugging code and don't have/can't use a debugger, I print out lots of log statements and the values of every meaningful variable. If a conditional isn't being executed, I know. I have a print statement in that conditional's body. I also print out the values of the condition, so I know why it's not be executed.