Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise 7.3 (Extra credit) Write a JavaScript program which will simulate turtl

ID: 3736180 • Letter: E

Question

Exercise 7.3 (Extra credit) Write a JavaScript program which will simulate turtle graphics. You will use two dimensional array to represent a floor of 20 x 20. The commands that you can give to the turtle is Command meaning Pen up Pen down Turn right Turn left 1 2 4 Two commands means move forward 12 spaces. You can specify how many steps by change 12 to that value. For example 5, 3 means you enter 5 press the 5, 12 Print the 20 x 20 array End of data Your program will list the commands and their meaning. There are one textbox for user to enter command number, two buttons: one for send command, the other one for process the commands sent. The following shows the screen shot

Explanation / Answer

Please find the anwser below//

<div>

<ul>

<li>1: Pen Up </li>

<li>2: Pen Down </li>

<li>3: Turn Right</li>

<li>4: Turn Left </li>

<li>5,10: Move forward 10 spaces</li>

<li>6: Print 20 by 20 array </li>

<li>6: End Of Array </li>

<li> Note Enter 5 as 2 commands </li>

</ul>

<br>

<input type="text" id="takeInput" />

<button id="SubmitButton">Submit Button</button>

<button id="ProcessCommand">Process Commands</button>

<div>

<div id="turtle"></div>

</div>

</div>

<script>

var arr = [];

arr = [2, 5, 10, 3, 5, 10, 3, 5, 10, 3, 5, 10, 1, 6 ,9];

var cursor = '';

var text = ' * ';

function insertArr(){

var x = document.getElementById("takeInput").value;

arr.push(x);

document.getElementById("takeInput").value = '';

}

function drawT(a){

for(var i=0; i<a; i++ ){

text = text + ' * ';

}

text = '';

document.getElementById("turtle").innerHTML = text;

}

//function drawturtle()

// 2 5 10 3 5 10 3 5 10 3 5 10 1 6 9

function drawturtle(item, index) {

//alert();

x = item;

if(x==1){

cursor = 'up';

//move(1,'up');

}

if(x==2){

cursor = 'down';

//move(2,'down');

}

if(x==3){

cursor = 'right';

//move(3,'right');

}

if(x==4){

cursor = 'left';

//move(4,'left');

}

if(x==5){

//cursor = 'up';

drawT(arr[index + 1]);

}

if(x==6){

//

//printTurtle();

}

if(x==9){

//gffg

var cv = 'prrr';

}

}

//arr.forEach('drawturtle');

</script>

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Happy Coding

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote