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.
// // 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”))];
// // 2
// Initialize the fortunes, luckyColorCode, and luckyColorName lists with
// data from ‘Fortune Data’
// // 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();
// // 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();
});
// // 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]);
}
// // 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.
}
// // 7
function addFortuneData(){
// Use the appendItem command to add at least one new element to all three lists:
// fortunes, luckyColorCode, and luckyColorName
}