Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ <h2>Indexing and slicing of matrices</h2>
<input class="btn" name="indexMatrix" id="indexMatrix" placeholder="index" type="number" />
</p>

<p>
<input type="button" class="btn btn-primary" value="access sub index" onclick="accessSubMatrix();" />
<input class="btn" name="subIndexMatrix" id="subIndexMatrix" placeholder="sub index" type="number" />
</p>

<p>
<input type="button" class="btn btn-primary" value="access matrix" onclick="accessMiddleMatrix();" />
</p>

</div>
</td>
<td id="textbox">
Expand Down
35 changes: 35 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ const memorySize = () => {
}

// Indexing and slicing of matrices
let indexMatrix = document.getElementById("indexMatrix");
let subIndexMatrix = document.getElementById("subIndexMatrix");

const accessMatrix = () => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'variable' field.");
Expand All @@ -97,3 +100,35 @@ const accessMatrix = () => {
document.editor.textbox.value+= "\n" + variable.value + "[" + indexMatrix.value + "]";
}
}

const accessSubMatrix = () => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'variable' field.");
} else if (Math.abs(Number(variable.value)) >= 0) {
return alert("Please do not enter a number in the 'variable' field.");
} else if (indexMatrix.value === "") {
return alert("Please enter a number in the 'index' field.")
} else if (subIndexMatrix.value === "") {
return alert("Please enter a number in the 'sub index' field.")
} else {
document.editor.textbox.value+= "\n" + variable.value + "[" + indexMatrix.value + ", " + subIndexMatrix.value + "]";
}
}

const accessMiddleMatrix = () => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'variable' field.");
} else if (Math.abs(Number(variable.value)) >= 0) {
return alert("Please do not enter a number in the 'variable' field.");
} else if (start1Matrix.value === "") {
return alert("Please enter a number in the 'start 1' field.")
} else if (end1Matrix.value === "") {
return alert("Please enter a number in the 'end 1' field.")
} else if (start2Matrix.value === "") {
return alert("Please enter a number in the 'start 2' field.")
} else if (end2Matrix.value === "") {
return alert("Please enter a number in the 'end 2' field.")
} else {
document.editor.textbox.value+= "\n" + variable.value + "[" + start1Matrix.value + ":" + end1Matrix.value + ", " + start2Matrix.value + ":" + end2Matrix.value + "]";
}
}