-1

I was trying to determine the size of this rectangle by the user:

<svg width=parseFloat(Rectangle1.width) height=parseFloat(Rectangle1.height)>
  <rect width=parseInt(input1int) height=parseInt(input2int) style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)" />
</svg>

with this code:

class Rectangle{
  constructor(height, width){
    this.height = height;
    this.width = width;
    };
  function createRectangle(this.height,this.width){
    var input1 = document.getElementbyId("1stinput").value;
    var input2 = document.getElementbyId("#2ndinput").value;
    var input1int = parseFloat(input1);
    var input2int = parseFloat(input2);
    var Rectangle1 = new Rectangle(this.height=input1int, this.width=input2int);};
};

but I got a whole of five errors to me:

Uncaught SyntaxError: Unexpected identifier
index.html:25 Error: <svg> attribute width: Expected length, "parseFloat(Recta…".
index.html:25 Error: <svg> attribute height: Expected length, "parseFloat(Recta…".
index.html:26 Error: <rect> attribute width: Expected length, "parseInt(input1i…".
index.html:26 Error: <rect> attribute height: Expected length, "parseInt(input2i…".

I don't know what they mean,so I'm once again asking for your financial coding support.

1 Answers1

1

That is not valid html. If you want to set width of an element dynamically. You must set it in JavaScript. Like

document.querySelector("svg").setAttribute('width', parseFloat(Rectangle1.width))
Han Moe Htet
  • 692
  • 1
  • 6
  • 10