I have the following code in my computational layer of a math response box. The lines that are not commented out currenly work, but don’t account for when the answer has an exponent of 0 and the student doesn’t enter the exponent (which is OK). So I attempted to fix that by entering commenting out the lines that are currently working and changing them to the lines commented out here. When I do that I get an error when entering a value with and exponent component. Even when my warning is commented out also. The message is that it cannont evaluate the entry. My project is [here]
(High School Placement Test Practice • Activity Builder by Desmos Classroom) The problem child is screen 7.
set up the pattern required
pattern = p.product(p.number,p.exponent(p.literal(“x”),p.integer))
matches = pattern.matches(this.latex)
warning: when not(matches) “Enter answer as Coefficient with variable x and exponent on the x variable.” otherwise “”
set up the pattern required REPLACED ABOVE 3 STATEMENTS WITH 6 STATEMENTS BELOW
#patternE = p.product(p.number,p.exponent(p.literal(“x”),p.integer))
#patternNoE = p.integer
#matchE = patternE.matches(this.latex)
#matchNoE = patternNoE.matches(this.latex)
#matches = matchE or matchNoE
#warning: when not(matches) “Enter answer as Coefficient with variable x and exponent on the x variable.” otherwise “”
separate the expression parts
coefficient = pattern.parse(this.latex).term1.numericValue
exponent = numericValue(pattern.parse(this.latex).term2.exponent.latex)
separate the expression parts REPLACED ABOVE 2 STATEMENTS WITH 2 STATEMENTS BELOW
#coefficient = when matchNoE this.numericValue otherwise patternE.parse(this.latex).term1.numericValue
#exponent = when matchNoE 0 otherwise numericValue(patternE.parse(this.latex).term2.exponent.latex)