Unit 6 Lesson 3 Level 3 - Need help with student bug

My student gets all the fortunes displayed when she runs this code for the Magic 9 Ball. I need some fresh eyes to see what we can’t see to identify where the bug is.

// :one: // 1
// Declare lists named fortunes, luckyColorCode, and luckyColorName
var fortunes = [(getColumn(“Fortune Data”, “Fortunes”))];
var luckyColorName = [(getColumn(“Fortune Data”, “Color Name”))];
var luckyColorCode = [(getColumn(“Fortune Data”, “Lucky Color”))];

// :two: // 2
// Initialize the fortunes, luckyColorCode, and luckyColorName lists with
// data from ‘Fortune Data’

// :three: // 3
// Create two index variables: one for reading elements from the fortune list and the
// other from reading from both the luckyColorCode/luckyColorName lists.
var fortuneIndex = 0 ;
var colorIndex = 0;

addFortuneData();

// :four: // 4
onEvent(“fortuneButton”, “click”, function( ) {
// Swaps out the 9 image for the text box element for displaying fortunes
showElement(“fortuneText”);
hideElement(“9NumberImage”);

// Implement the Random List Access Pattern to choose a random fortune from the
// fortunes list and display it into the fortuneText text area.
fortuneIndex = randomNumber(0, fortunes.length-1);
setProperty(“fortuneText”, “text”, fortunes[fortuneIndex]);

setLuckyColor();

});

// :five: // 5
function setLuckyColor(){
// Implement the List Scrolling Pattern to increment through both luckyColorName/luckyColorCode
// When you reach the end of the list, return to an index of 0
if (colorIndex < luckyColorName.lenght-1) {
colorIndex = colorIndex+1;
} else {
colorIndex = 0;
}

// Display the name of the lucky color in the ‘luckyColorTextBox’ element from the luckyColorName list
setProperty(“luckyColorTextBox”, “text”, luckyColorName[colorIndex]);

// Change the ‘background-color’ property of the ‘bgColor’ element to match the value in the
// luckyColorCode list
// setProperty(“bgColor”, “background-color”, luckyColorCode[colorIndex]);

}

// :six: // 6
function setLuckyNumber(){
// Declare a new local variable ‘luckyNumber’. Initialize to the value of our two index variables
// muliplied together. Display luckyNumber in the ‘luckyNumberTextBox’ element.

}

// :seven: // 7
function addFortuneData(){
// Use the appendItem command to add at least one new element to all three lists:
// fortunes, luckyColorCode, and luckyColorName

}

Hello, I haven’t run your code to see whether this fixes the bug, but the student should not surround the getColumn() with [ ]. The getColumn() command already returns the information as a list.
The correct use of getColumn would be
var fortunes = getColumn(“Fortune Data”, “Fortunes”);

I hope this is helpful,
Anne Trachsel

2 Likes

Thank you for your observation

@randle.moore I went through and made the change Anne suggested above. I also noticed in Line 38, the student wrote “lenght” when they meant “length”:
image

The project appears to be working after I made these changes: link to sample I just made. Can you verify with the student that it’s doing what they expect it to be doing, and if not, share a link to their project so we can continue troubleshooting? It’s easier for us to work from a link to Code Studio so we can see exactly what they’re seeing.

I would also recommend looking at the Debug Console as that usually gives you an idea of where to look when things are misbehaving.

Thanks!

–Michael K.

1 Like