SlideShare a Scribd company logo
I need to create a page looks like a picture. But it looks different.
My html
Assignment 8Shapes Exercise
SquareCircleTriangleAdd to ArrayRemove LastDraw Shapes
My Js
let shapeArray = [];
const shapeSelect = document.getElementById("shapeSelect");
const addBtn = document.getElementById("addBtn");
const removeBtn = document.getElementById("removeBtn");
const drawBtn = document.getElementById("drawBtn");
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
addBtn.addEventListener("click", function () {
const selectedShape = shapeSelect.value;
if (shapeArray.length < 5) {
shapeArray.push(selectedShape);
} else {
alert("You cannot add more than 5 shapes to the array.");
}
});
removeBtn.addEventListener("click", function () {
shapeArray.pop();
});
function drawCircle(x, y) {
ctx.beginPath();
ctx.arc(x, y, 50, 0, 2 * Math.PI);
ctx.stroke();
}
function drawTriangle(x, y) {
const sideLength = 100;
const height = sideLength * Math.sqrt(3) / 2;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + sideLength / 2, y + height);
ctx.lineTo(x - sideLength / 2, y + height);
ctx.closePath();
ctx.stroke();
}
function drawSquare(x, y) {
ctx.beginPath();
ctx.rect(x, y, 100, 100);
ctx.stroke();
}
drawBtn.addEventListener("click", function () {
ctx.clearRect(0, 0, canvas.width, canvas.height);
shapeArray.forEach(function (shape, index) {
switch (shape) {
case"circle":
drawCircle(50 + index * 150, 100);
break;
case"triangle":
drawTriangle(50 + index * 150, 100);
break;
case"square":
drawSquare(50 + index * 150, 100);
break;
default:
console.error("Unknown shape: " + shape);
break;
}
});
});
let shapeArray = [];
const shapeSelect = document.getElementById("shapeSelect");
const addBtn = document.getElementById("addBtn");
const removeBtn = document.getElementById("removeBtn");
const drawBtn = document.getElementById("drawBtn");
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
addBtn.addEventListener("click", function () {
const selectedShape = shapeSelect.value;
if (shapeArray.length < 5) {
shapeArray.push(selectedShape);
} else {
alert("You cannot add more than 5 shapes to the array.");
}
});
removeBtn.addEventListener("click", function () {
shapeArray.pop();
});
function drawCircle(x, y) {
ctx.beginPath();
ctx.arc(x, y, 50, 0, 2 * Math.PI);
ctx.stroke();
}
function drawTriangle(x, y) {
const sideLength = 100;
const height = sideLength * Math.sqrt(3) / 2;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + sideLength / 2, y + height);
ctx.lineTo(x - sideLength / 2, y + height);
ctx.closePath();
ctx.stroke();
}
function drawSquare(x, y) {
ctx.beginPath();
ctx.rect(x, y, 100, 100);
ctx.stroke();
}
drawBtn.addEventListener("click", function () {
ctx.clearRect(0, 0, canvas.width, canvas.height);
shapeArray.forEach(function (shape, index) {
switch (shape) {
case"circle":
drawCircle(50 + index * 150, 100);
break;
case"triangle":
drawTriangle(50 + index * 150, 100);
break;
case"square":
drawSquare(50 + index * 150, 100);
break;
default:
console.error("Unknown shape: " + shape);
break;
}
});
});
let shapeArray = [];
const shapeSelect = document.getElementById("shapeSelect");
const addBtn = document.getElementById("addBtn");
const removeBtn = document.getElementById("removeBtn");
const drawBtn = document.getElementById("drawBtn");
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
addBtn.addEventListener("click", function () {
const selectedShape = shapeSelect.value;
if (shapeArray.length < 5) {
shapeArray.push(selectedShape);
} else {
alert("You cannot add more than 5 shapes to the array.");
}
});
removeBtn.addEventListener("click", function () {
shapeArray.pop();
});
function drawCircle(x, y) {
ctx.beginPath();
ctx.arc(x, y, 50, 0, 2 * Math.PI);
ctx.stroke();
}
function drawTriangle(x, y) {
const sideLength = 100;
const height = sideLength * Math.sqrt(3) / 2;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + sideLength / 2, y + height);
ctx.lineTo(x - sideLength / 2, y + height);
ctx.closePath();
ctx.stroke();
}
function drawSquare(x, y) {
ctx.beginPath();
ctx.rect(x, y, 100, 100);
ctx.stroke();
}
drawBtn.addEventListener("click", function () {
ctx.clearRect(0, 0, canvas.width, canvas.height);
shapeArray.forEach(function (shape, index) {
switch (shape) {
case"circle":
drawCircle(50 + index * 150, 100);
break;
case"triangle":
drawTriangle(50 + index * 150, 100);
break;
case"square":
drawSquare(50 + index * 150, 100);
break;
default:
console.error("Unknown shape: " + shape);
break;
}
});
}); Exercise 11 Draw Shapes

More Related Content

PDF
Exploring Canvas
PPTX
Css5 canvas
KEY
Exploring Canvas
PDF
Create a java project that - Draw a circle with three random init.pdf
PDF
I need to create a page that looks like the picture The pro.pdf
PDF
UI Design From Scratch - Part 5 - transcript.pdf
PPTX
HTML5 Canvas (Wall Clock).pptx
PPTX
How to make a video game
Exploring Canvas
Css5 canvas
Exploring Canvas
Create a java project that - Draw a circle with three random init.pdf
I need to create a page that looks like the picture The pro.pdf
UI Design From Scratch - Part 5 - transcript.pdf
HTML5 Canvas (Wall Clock).pptx
How to make a video game

Similar to I need to create a page looks like a picture. But it looks different.pdf (20)

PPT
Supstat nyc subway
PPTX
Making Games in JavaScript
PDF
Creating an Uber Clone - Part VIII.pdf
PDF
You will learn RxJS in 2017
PDF
QML\Qt Quick на практике
PPTX
Canvas al ajillo
PDF
package chapter15;import javafx.application.Application;import j.pdf
PDF
Computer Graphics in Java and Scala - Part 1b
PDF
Introduction to d3js (and SVG)
PDF
Presentation Canvas for RSScholl 2025/04
DOCX
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
PDF
Prototype programming in JavaScript
PPTX
PDF
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
PDF
Having fun with graphs, a short introduction to D3.js
PPTX
Raspberry Pi à la GroovyFX
PPTX
Game dev 101 part 3
DOCX
Cara membuat tulisan mengikuti kursor di blog
PDF
I need to create a page like a picture My code is working .pdf
PDF
Creating an Uber Clone - Part VIII - Transcript.pdf
Supstat nyc subway
Making Games in JavaScript
Creating an Uber Clone - Part VIII.pdf
You will learn RxJS in 2017
QML\Qt Quick на практике
Canvas al ajillo
package chapter15;import javafx.application.Application;import j.pdf
Computer Graphics in Java and Scala - Part 1b
Introduction to d3js (and SVG)
Presentation Canvas for RSScholl 2025/04
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
Prototype programming in JavaScript
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Having fun with graphs, a short introduction to D3.js
Raspberry Pi à la GroovyFX
Game dev 101 part 3
Cara membuat tulisan mengikuti kursor di blog
I need to create a page like a picture My code is working .pdf
Creating an Uber Clone - Part VIII - Transcript.pdf
Ad

More from allurafashions98 (20)

PDF
Current Attempt in Progress. At December 31, 2024, Culiumber Imports .pdf
PDF
Current Attempt in Progress Waterway Company uses a periodic inventor.pdf
PDF
Current Attempt in Progress The comparative balance.pdf
PDF
Current Attempt in Progress Novaks Market recorded the following eve.pdf
PDF
Current Attempt in Progress Ivanhoe Corporation reported the followin.pdf
PDF
Define a class called Disk with two member variables, an int called.pdf
PDF
Define to be the median of the Exponential () distribution. That is,.pdf
PDF
Dedewine the bridthenes tar this test Choose the conist answet below .pdf
PDF
Davenport Incorporated has two divisions, Howard and Jones. The f.pdf
PDF
Data tableRequirements 1. Prepare the income statement for the mon.pdf
PDF
Current Attempt in Progress Items from Oriole Companys budget for Ma.pdf
PDF
Data tableAfter researching the competitors of EJH Enterprises, yo.pdf
PDF
Current Attempt in Progress If a qualitative variable has c categ.pdf
PDF
Data tableData tableThe figures to the right show the BOMs for .pdf
PDF
Data table Requirements 1. Compute the product cost per meal produced.pdf
PDF
Darla, Ellen, and Frank have capital balances of $30,000,$40,000 and .pdf
PDF
Daniel, age 38 , is single and has the following income and exnencac .pdf
PDF
Danny Anderson admired his wifes success at selling scarves at local.pdf
PDF
CX Enterprises has the following expected dividends $1.05 in one yea.pdf
PDF
Daring the financial crisis an the end of the firs decade of the 2000.pdf
Current Attempt in Progress. At December 31, 2024, Culiumber Imports .pdf
Current Attempt in Progress Waterway Company uses a periodic inventor.pdf
Current Attempt in Progress The comparative balance.pdf
Current Attempt in Progress Novaks Market recorded the following eve.pdf
Current Attempt in Progress Ivanhoe Corporation reported the followin.pdf
Define a class called Disk with two member variables, an int called.pdf
Define to be the median of the Exponential () distribution. That is,.pdf
Dedewine the bridthenes tar this test Choose the conist answet below .pdf
Davenport Incorporated has two divisions, Howard and Jones. The f.pdf
Data tableRequirements 1. Prepare the income statement for the mon.pdf
Current Attempt in Progress Items from Oriole Companys budget for Ma.pdf
Data tableAfter researching the competitors of EJH Enterprises, yo.pdf
Current Attempt in Progress If a qualitative variable has c categ.pdf
Data tableData tableThe figures to the right show the BOMs for .pdf
Data table Requirements 1. Compute the product cost per meal produced.pdf
Darla, Ellen, and Frank have capital balances of $30,000,$40,000 and .pdf
Daniel, age 38 , is single and has the following income and exnencac .pdf
Danny Anderson admired his wifes success at selling scarves at local.pdf
CX Enterprises has the following expected dividends $1.05 in one yea.pdf
Daring the financial crisis an the end of the firs decade of the 2000.pdf
Ad

Recently uploaded (20)

PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
Computing-Curriculum for Schools in Ghana
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
20th Century Theater, Methods, History.pptx
PDF
Hazard Identification & Risk Assessment .pdf
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
HVAC Specification 2024 according to central public works department
PDF
My India Quiz Book_20210205121199924.pdf
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Computing-Curriculum for Schools in Ghana
Indian roads congress 037 - 2012 Flexible pavement
What if we spent less time fighting change, and more time building what’s rig...
Weekly quiz Compilation Jan -July 25.pdf
Paper A Mock Exam 9_ Attempt review.pdf.
20th Century Theater, Methods, History.pptx
Hazard Identification & Risk Assessment .pdf
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
AI-driven educational solutions for real-life interventions in the Philippine...
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Virtual and Augmented Reality in Current Scenario
HVAC Specification 2024 according to central public works department
My India Quiz Book_20210205121199924.pdf
B.Sc. DS Unit 2 Software Engineering.pptx
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
FORM 1 BIOLOGY MIND MAPS and their schemes
LDMMIA Reiki Yoga Finals Review Spring Summer

I need to create a page looks like a picture. But it looks different.pdf

  • 1. I need to create a page looks like a picture. But it looks different. My html Assignment 8Shapes Exercise SquareCircleTriangleAdd to ArrayRemove LastDraw Shapes My Js let shapeArray = []; const shapeSelect = document.getElementById("shapeSelect"); const addBtn = document.getElementById("addBtn"); const removeBtn = document.getElementById("removeBtn"); const drawBtn = document.getElementById("drawBtn"); const canvas = document.getElementById("canvas"); const ctx = canvas.getContext("2d"); canvas.width = window.innerWidth; canvas.height = window.innerHeight; addBtn.addEventListener("click", function () { const selectedShape = shapeSelect.value; if (shapeArray.length < 5) {
  • 2. shapeArray.push(selectedShape); } else { alert("You cannot add more than 5 shapes to the array."); } }); removeBtn.addEventListener("click", function () { shapeArray.pop(); }); function drawCircle(x, y) { ctx.beginPath(); ctx.arc(x, y, 50, 0, 2 * Math.PI); ctx.stroke(); } function drawTriangle(x, y) { const sideLength = 100; const height = sideLength * Math.sqrt(3) / 2; ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x + sideLength / 2, y + height); ctx.lineTo(x - sideLength / 2, y + height); ctx.closePath(); ctx.stroke(); } function drawSquare(x, y) { ctx.beginPath(); ctx.rect(x, y, 100, 100); ctx.stroke(); } drawBtn.addEventListener("click", function () {
  • 3. ctx.clearRect(0, 0, canvas.width, canvas.height); shapeArray.forEach(function (shape, index) { switch (shape) { case"circle": drawCircle(50 + index * 150, 100); break; case"triangle": drawTriangle(50 + index * 150, 100); break; case"square": drawSquare(50 + index * 150, 100); break; default: console.error("Unknown shape: " + shape); break; } }); }); let shapeArray = []; const shapeSelect = document.getElementById("shapeSelect"); const addBtn = document.getElementById("addBtn"); const removeBtn = document.getElementById("removeBtn"); const drawBtn = document.getElementById("drawBtn"); const canvas = document.getElementById("canvas"); const ctx = canvas.getContext("2d"); canvas.width = window.innerWidth; canvas.height = window.innerHeight; addBtn.addEventListener("click", function () { const selectedShape = shapeSelect.value;
  • 4. if (shapeArray.length < 5) { shapeArray.push(selectedShape); } else { alert("You cannot add more than 5 shapes to the array."); } }); removeBtn.addEventListener("click", function () { shapeArray.pop(); }); function drawCircle(x, y) { ctx.beginPath(); ctx.arc(x, y, 50, 0, 2 * Math.PI); ctx.stroke(); } function drawTriangle(x, y) { const sideLength = 100; const height = sideLength * Math.sqrt(3) / 2; ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x + sideLength / 2, y + height); ctx.lineTo(x - sideLength / 2, y + height); ctx.closePath(); ctx.stroke(); } function drawSquare(x, y) { ctx.beginPath(); ctx.rect(x, y, 100, 100); ctx.stroke(); }
  • 5. drawBtn.addEventListener("click", function () { ctx.clearRect(0, 0, canvas.width, canvas.height); shapeArray.forEach(function (shape, index) { switch (shape) { case"circle": drawCircle(50 + index * 150, 100); break; case"triangle": drawTriangle(50 + index * 150, 100); break; case"square": drawSquare(50 + index * 150, 100); break; default: console.error("Unknown shape: " + shape); break; } }); }); let shapeArray = []; const shapeSelect = document.getElementById("shapeSelect"); const addBtn = document.getElementById("addBtn"); const removeBtn = document.getElementById("removeBtn"); const drawBtn = document.getElementById("drawBtn"); const canvas = document.getElementById("canvas"); const ctx = canvas.getContext("2d"); canvas.width = window.innerWidth; canvas.height = window.innerHeight; addBtn.addEventListener("click", function () { const selectedShape = shapeSelect.value; if (shapeArray.length < 5) { shapeArray.push(selectedShape); } else { alert("You cannot add more than 5 shapes to the array.");
  • 6. } }); removeBtn.addEventListener("click", function () { shapeArray.pop(); }); function drawCircle(x, y) { ctx.beginPath(); ctx.arc(x, y, 50, 0, 2 * Math.PI); ctx.stroke(); } function drawTriangle(x, y) { const sideLength = 100; const height = sideLength * Math.sqrt(3) / 2; ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x + sideLength / 2, y + height); ctx.lineTo(x - sideLength / 2, y + height); ctx.closePath(); ctx.stroke(); } function drawSquare(x, y) { ctx.beginPath(); ctx.rect(x, y, 100, 100); ctx.stroke(); } drawBtn.addEventListener("click", function () { ctx.clearRect(0, 0, canvas.width, canvas.height); shapeArray.forEach(function (shape, index) { switch (shape) { case"circle": drawCircle(50 + index * 150, 100); break; case"triangle": drawTriangle(50 + index * 150, 100); break; case"square":
  • 7. drawSquare(50 + index * 150, 100); break; default: console.error("Unknown shape: " + shape); break; } }); }); Exercise 11 Draw Shapes