Problem With App Lab Creation

Hey Guys,

I have a student who has created a quiz in app lab, the only problem is that we can’t figure out why the correct answers won’t add up. At most it states 1 correct answer no matter how many you get right? As a first year Computer Science Teacher I would be grateful for any help you could give.


If you put a console.log inside checkCorrect you’ll see what’s happening. Try something like:

console.log(guess + " | " + correctState);

I inserted that at line 93.

The reason correct is 1 is because you call it on line 12 with no arguments - it evaluates undefined == undefined and says you’re correct.

We tried console.log on line 93, it just showed the answer choices that you selected. On the console.log(guess + “I” + correctState); does the I stand for index or iterator or what? Also do we have to have the call function checkCorrect on line 12? I was assuming we did because we have a checkCorrect define function.

Let’s look at this code:

function checkCorrect(guess, correctState) {
  //add point to score
  if (guess == correctState) {
    score = score + 1;
    setText("attemptLabel", getText("attemptLabel"));

You are comparing the value of guess to the value of correctState. Let’s now look at what those values might be.

As we can see the value of guess is the text of one of four buttons.

onEvent("answer1", "click", function( ) {
	guess = getText("answer1");
	checkCorrect(guess, correctState);

Okay, so where does that come from?

        setText("answer"+randAnswerChoice, capitalNameList[index]);

It comes from the array capitalNameList. That comes from the database getColumn("US States", "Capital");.

So now where does correctState come from?

    correctState = stateNameList[index];

And what is in stateNameList? We get that from the database too getColumn("US States", "State Name");

So you are comparing values from “State Name” to values from “Capital”. Will those ever be equal?

Do you recommend changing line 50 to correct capital instead of correct state?

var index = randomNumber(0, stateNameList.length-1);
correctCapital = capitalNameList[index];
setImageURL(“imageOutput”, imageList[index]);
setText(“answer1”, capitalNameList[index]);
setText(“answer2”, capitalNameList[index]);
setText(“answer3”, capitalNameList[index]);
setText(“answer4”, capitalNameList[index]);

And line 92 to guess == correctCapital ?

function checkCorrect(guess, correctCapital) {
//add point to score
if (guess == correctCapital) {
score = score + 1;

I would make that change and then test it again.

I have a student working on his Decision Maker App for Unit 4.

The “else” in line 26 is not executing somehow. Random number generation is occurring, and shows up in the console log, but the result always shows 10. Maybe it’s something to do with the refreshing of the screen not being coded in right?

Anyone have an idea as to what might be missing here?


Thank you!!!

1 Like

Hi @a.digiovanni,

I like the app that student made! Their main issue is in line 22. I would encourage them to look up what the randomNumber function does and what parameters it needs.

There’s also an issue on line 47 that needs to be cleared up in the case that the user doesn’t use the dropdown menu. Ask the student to think about that & come back here if you need more help!

–Michael K.