Forum Discussion

Allitha_Works's avatar
Allitha_Works
Community Member
16 days ago
Solved

Using a number variable to move an image on x axis

Hi All

I am trying to figure out if it is possible to move a image based on a numeric entry. 

The idea is that the learner will enter a value and the arrow will move left and right as the number changes. The learner will then have to submit the final number to get correct or incorrect feedback.

I added some screenshots to help illustrate the basic idea.

Orange shows the beginning position on the ruler, e.g. 0mm = 60px x-position.
Green is the length of the bolt, e.g. 1,5mm = 180px x-position.
The formulae to get the position would be (Number Entry X 80) + 60px.

I tried the code below, but it can't get it to work.

const triangleOrange = object('6L80cB1zfRN');
const numericValue = GetVar('NumericEntry_800'); // Retrieve value entered by learner

// Calculate x-position dynamically
const newX = (numericValue * 80) + 60; 

triangleOrange.x = newX; // Update position

Any help will be appreciated!

  • I think you should change "GetVar()" to "getVar()" 

2 Replies

  • Nedim's avatar
    Nedim
    Community Member

    I think you should change "GetVar()" to "getVar()"