Closed jonasjul closed 1 year ago
Question 4 does use multiple jsxgraph boards, not sure if there is a version of question 1 which uses multiple jsxgraph boards.
function getNextDivId(currentId) {
// Extract the number at the end of the currentId string
var num = currentId.match(/\d+$/);
// Increment the number by 1
num = parseInt(num, 10) + 1;
// Return the new div id by replacing the number at the end of the currentId string with the incremented number
return currentId.replace(/\d+$/, num);
}
// example
var divid = "stack-jsxgraph-1";
var divid2 = getNextDivId(divid); // this outputs "stack-jsxgraph-2"
Questions 1 and 4 uses multiple jsxgraph boards, and the divid for the second board is "hard-coded" in the javascript code:
var divid2 = "stack-jsxgraph-2"
This won't work in a real-life context, and the second div-id needs to be determined from the "current" divid (ie. increment/decrement number at the end of id)Maybe check out regexp in javascript here and here