Formula questions and modifications of random variables

Jump to solution
dmacdonald85
Community Member

Hi everyone,

I am trying to solve the following problem. Say I have created a random variable x, which I display to the student using [x] in the Canvas formula question. I know how to do this. 

How can I then display to the student the value x+5? If I try [x+5] or [[x]+5], it doesn't work. Basically, I want some code that will appear to the student as x+5 after I've created the variable x. How can I do this?

Thanks for any help you can offer!

Labels (1)
0 Likes
1 Solution
James
Community Champion

@dmacdonald85 

What you're asking for is not directly possible with Canvas. There are a few things that you can do.

  1. Make them numeric questions rather than formula questions and create multiple versions of the same question and put them into a bank / question group. I would use Excel or some kind of programming language to generate the question text and then copy/paste that into the new questions.
  2. Use the technique I explained in Using Calculated Values in the Text of Formula Questions. You would need to create a variable for each row, call them a, b, c, d, f, g, etc. Then generate a random number and edit the rest.
  3. There is an Chrome extension (I didn't write it and don't know it's full capabilities) to extra functionality to random number generation. You have to install it to see how to use it. The author mentioned it 5 times in the Community, but never more (that I can find right now) than it is available. It's linked to a few times in the comments to link I gave in #2.
  4. You can use Python or another programming language to completely generate the questions with the copy/paste steps in #1. There's a link in the comments of the blog post I wrote in #2.

Note: I have used numbered variables in the past with Classic Quizzes. x1, x2, x3, x4. When I tried it just now, Canvas complained about my undefined variables x1, x2, x3, x4. It shows them in the random number specification section but complains when you go to use them in a calculation. For now, you could use [x] as the first one and then x1, x2, x3 as others, but there's no guarantee it would continue to work if Canvas is breaking stuff on the back end that has worked for decades.

Based on that, I just added a non-numbered variable, x, first, and then the numbered ones worked. Seems buggy, but unlikely to be fixed.

Make sure you avoid [e] as a variable since Canvas treats it as the base for natural logarithms and not a constant.

Here is some code that will do what you describe. Since I don't know your entire question, I just use the base part.

Question: The demand quantities are [x], [x1], [x2], and [x3] ...

Variable Definitions: Decide what you want for x. Leave x1, x2, and x3 as anything since we're going to overwrite them.

Now create and save the formula and generate possible solutions.

Open the developer tools as explained in my post, switch to the console tab, and paste this code. Hit enter to execute.

document.querySelectorAll('table.combinations tbody tr').forEach(row => {
  const col = row.querySelectorAll('td');
  const x = parseInt(col[0].textContent, 10);
  for (let n = 1; n <= 3; n++) {
    col[n].textContent = x + 5 * n;
  }
});

That code assumes that x is in column 0 (first column). If you have other variables before x, you would need to adjust the subscript in the parseInt() line and the line within the for loop. For example, if x was in the third column, then its subscript would be 2. You use col[2] instead of col[0] and col[2+n] rather than col[n]. I also put in 3 since you had 3 generated columns. You should modify that if needed.

To answer the other questions you asked @james_whalley, I'm not a Canvas Developer either, I'm a math professor. Canvas support for the formula questions is limited, so they don't support what you're asking about with the shifting.  We [math, science, technology] have been wanting advanced capabilities for years and it never goes anywhere. We're too niche to widely support. They would rather leave that to some third party and provide the platform that the tool can plug into.

To what James Whalley asked, there's a huge readability difference between 4, 9, 14 and 4, 4+5, 4+10. Mathematically, they are equivalent. But you want to ask the question in the most normal way possible and no textbook or instructor is ever going to say the demand quantities are 4, 4+5, 4+10. 

One of the guidelines for creating a good visualization is to do the math for the person. That makes it easier for them to focus on what you want them to focus on. Here, you don't want the student to get confused over interpreting what 4+15 means, especially if that 4 happens to be 117. They will likely need to do something with that 132 number rather than just knowing they are spaced five units apart. Showing +5, +10, +15 puts more emphasis on the 5 units part, detracting from the real problem.

View solution in original post