After an outage on September 1, the Instructure Community is now fully available, including guides, release notes, forums, and groups. If some styling still looks unusual, clear your cache and cookies.
Found this content helpful? Log in or sign up to leave a like!
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!
Solved! Go to Solution.
What you're asking for is not directly possible with Canvas. There are a few things that you can do.
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.
Hello @dmacdonald85,
From the testing I just did, entering it as [x]+5 worked for me. When previewing the quiz, a different number is generated each time for x, but it is always "+5". Can you try that and see if it works for you?
--James
Thanks for your reply! This didn't work for me. I can give you a bit more of a context. Say I want the quiz to say "The demand quantities are [x], [x]+5, [x]+10, and [x]+15...". I want the quiz to generate a random number x and then report the 5-unit increments of x as well. So let's say x is randomly generate to 100. I want the quiz text to be "The demand quantities are 100, 105, 110, and 115...". But appending [x]+5 does not work for me when I enter preview.
So what you want to do is create a new variable for each, and set each variable to x+n that you want.
So let's say you have "the demand quantities are x, y, z, w"
and you set y = x+5, z = x+10, w = x+15
Ahhh...
This is not possible in either Quizzes or New Quizzes as far as I can tell. That said, though the values you having are not automatically calculating as you would like, they are conveying the same information.
For example:
Demand quantities are x, x+5, x+10, and so on.
x = 4
"Demand quantities are 4, 9, 14, and so on" has the same meaning as "Demand quantities are 4, 4+5, 4+10, and so on".
I may be missing the context that makes the integers appearing more important than the student having the list of quantities though.
Thanks James, I really appreciate having a kindred spirit on here to discuss these topics! Thank you for all your time!
I'm an economics instructor, and often we present our students with tables of data and have them extract some information from them. It would be nice if I could generate a full table of random data but which has some structure to it (as I am looking for here) to ask them some questions about it. If the data are too random, it may make the numbers less "believable" or even realistic.
Are you a Canvas developer? Another thing I would like to ask about Canvas is if it can support curve shifts; this could really break into the homework app market for economics. Suppose we have a demand and supply curve and ask a student to shift the demand curve in one direction or the other, for example.
Thanks again for your time! I will look for workaround solutions.
I am happy to help. I am actually an instructional design technologist at Cornell University and just spend some time in here paying it forward.
As for a table of random data with structure, I tried feeding that idea into ChatGPT and asking about doing that in Google Sheets. It popped out an interesting answer involving using RAND()
, RANDBETWEEN()
, and ARRAYFORMULA()
to help randomize data in a sheet that could then be used as a template.
As far as interactive graphs, I recommend you check out EconGraphs. We had an instructor who figured out how to use iframes to embed those graphs within questions in Canvas Quizzes.
Best,
James
What you're asking for is not directly possible with Canvas. There are a few things that you can do.
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.
To interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in