Skip to content
Permalink
Browse files

by val proficiency exercise model solution looks good.

  • Loading branch information...
CorySanin committed Jan 18, 2019
1 parent c7234a6 commit 6ec1f9d4a3ffa01ba0a5d16900ab54f75f20a0b6
Showing with 91 additions and 10 deletions.
  1. +91 −10 AV/PL/paramPassingByValPRO.js
@@ -93,34 +93,114 @@ $(document).ready(function () {

// Process About button: Pop up a message with an Alert
function about() {
alert(ODSA.AV.aboutstring(interpret(".avTitle"), interpret("av_Authors")));
alert(ODSA.AV.aboutstring('By Value proficiency exercise', 'Cory Sanin'));
}

// generates the model answer
function modelSolution(modeljsavAV) {
var currentTopMargin = 0;
var topMargin = 0;
var fooVars = {};
var classVars = {};
var mainVars = {};
var labelobj;
var currentLine = fooIndex;
function unhighlightAll(){
unhighlightElements(classVars);
unhighlightElements(mainVars);
unhighlightElements(fooVars);
}

var pseudo = modeljsavAV.code(codeLines,
{left: leftMargin, top: topMargin, lineNumbers: false}
);
jsavElements.push(pseudo);

//run foo()
for(var arr in initialArrays.fooVars){
fooVars[arr] = modeljsavAV.ds.array(initialArrays.fooVars[arr]);
jsavElements.push(fooVars[arr]);
}
for(arr in initialArrays.classVars){
classVars[arr] = modeljsavAV.ds.array(initialArrays.classVars[arr]);
jsavElements.push(classVars[arr]);
labelobj = modeljsavAV.label(arr,
{
relativeTo:pseudo, anchor:"right top", myAnchor:"left top",
left: leftMargin, top: currentTopMargin
}
);
classVars[arr] = modeljsavAV.ds.array(initialArrays.classVars[arr],
{
indexed: initialArrays.classVars[arr].length > 1,relativeTo:labelobj, anchor:"right top",
myAnchor:"left top", left: labelMargin,
top:-1*jsavArrayOffset
}
);
jsavElements.push(classVars[arr], labelobj);
currentTopMargin += lineHeight;
}

jsavElements.push(modeljsavAV.label("main",
{
relativeTo:pseudo, anchor:"right top", myAnchor:"left top",
left: leftMargin, top: currentTopMargin
}
));
var fooLabel = modeljsavAV.label("foo",
{
relativeTo:pseudo, anchor:"right top", myAnchor:"left top",
left: leftMargin+boxWidth+boxPadding*2, top: currentTopMargin
}
);
jsavElements.push(fooLabel);

currentTopMargin += lineHeight;

var numVars = Object.keys(initialArrays.fooVars).length;

jsavElements.push(modeljsavAV.g.rect(2*leftMargin+pseudo.element[0].clientWidth,
currentTopMargin+topMargin,
boxWidth,
lineHeight*numVars+boxPadding*numVars
));
jsavElements.push(modeljsavAV.g.rect(2*leftMargin+pseudo.element[0].clientWidth+boxWidth+
boxPadding*2,
currentTopMargin+topMargin,
boxWidth,
lineHeight*numVars+boxPadding*numVars
));

for(arr in initialArrays.mainVars){
mainVars[arr] = modeljsavAV.ds.array(initialArrays.mainVars[arr]);
jsavElements.push(mainVars[arr]);
labelobj = modeljsavAV.label(arr,
{
relativeTo:pseudo, anchor:"right top", myAnchor:"left top",
left: leftMargin, top: currentTopMargin
}
);
mainVars[arr] = modeljsavAV.ds.array(initialArrays.mainVars[arr],
{
indexed: initialArrays.mainVars[arr].length > 1,relativeTo:labelobj, anchor:"right top",
myAnchor:"left top", left: labelMargin,
top:-1*jsavArrayOffset
}
);
jsavElements.push(mainVars[arr], labelobj);
}
for(var arr in initialArrays.fooVars){
labelobj = modeljsavAV.label(arr,
{
relativeTo:pseudo, anchor:"right top", myAnchor:"left top",
left: leftMargin+boxWidth+3*boxPadding, top: currentTopMargin
}
);
fooVars[arr] = modeljsavAV.ds.array(initialArrays.fooVars[arr],
{
indexed: initialArrays.fooVars[arr].length > 1,relativeTo:labelobj, anchor:"right top",
myAnchor:"left top", left: labelMargin,
top:-1*jsavArrayOffset
}
);
jsavElements.push(fooVars[arr], labelobj);
currentTopMargin += lineHeight;
}

pseudo.setCurrentLine(++currentLine);

modeljsavAV.displayInit();

var contexts = [fooVars,classVars];
@@ -154,6 +234,7 @@ $(document).ready(function () {
modeljsavAV.umsg(outMsg);

modeljsavAV.gradeableStep();
pseudo.setCurrentLine(++currentLine);
}

var jsavArrs = {
@@ -189,7 +270,7 @@ $(document).ready(function () {
pseudo = av.code(codeLines,
{left: leftMargin, top: topMargin, lineNumbers: false}
);
jsavElements.push(pseudo)
jsavElements.push(pseudo);

for(var i = 0; i < fooIndex - 1; i++){
if(codeLines[i]){

0 comments on commit 6ec1f9d

Please sign in to comment.
You can’t perform that action at this time.