Unit 4, Lesson 11 - Quote Maker with no variables

Hello–I have a student who created the quote maker app with only onEvents and no variables (they were working ahead before I gave instructions for that lesson). It’s working, but I need help explaining why it’s preferred to do it the way prescribed in the activity guide.

I’m including the code for you to see. Thanks in advance!

onEvent("quoteInput", "input", function() {
  setText("quoteOutput", getText("quoteInput"));
});
onEvent("fontFamilyInput", "input", function() {
  setProperty("quoteOutput", "font-family", getText("fontFamilyInput"));
});
onEvent("colorInput", "input", function() {
  setProperty("colorOutput", "background-color", getText("colorInput"));
});
onEvent("fontSizeInput", "input", function() {
  setProperty("quoteOutput", "font-size", getNumber("fontSizeInput"));
});
onEvent("imageInput", "input", function() {
  setProperty("colorInput", "image", getText("imageInput"));
});

I would say that variables are always preferred to store the information in a program because if you want to update the program in any way and use the value, you would have to obtain it each time which is repetitive. If the vale is stored in a variable then if you update the program and want to use that value you simply reference the variable.

2 Likes