1

So I am trying to make a program that takes a user input that creates an ellipse. I have coded all the calculations that the input has to go through to develop the eqRad and polRad. I am trying to make these function parameters and I thought this should work (My code is below) but it doesn't. How would I get these parameters to work? Please know that I have a working function above the code snippet I just need to know how to get theses parameters to work. Thank you in advance!

let eqRad = Math.pow((1-Math.pow(e,2)),-1/6);
let polRad = Math.pow((1-Math.pow(e,2)),1/3);

makeEllipse(eqRad,polRad);

}

function makeEllipse(eqRad,polRad) {
  let svg = document.getElementById('diagram');

  let temp = document.getElementById('mydiagram');
  if (temp) {
    temp.remove();
  }

  let ellipse = document.createElementNS('http://www.w3.org/2000/svg', 'path');
  ellipse.setAttribute('d', 'M 400 200 a polRad,eqRad 90 1,0 1,0 z');
  ellipse.style.fill = 'white';
  ellipse.style.stroke = 'black';
  ellipse.style.strokeWidth = '5px';
  ellipse.setAttribute('id', 'mydiagram');
  svg.appendChild(ellipse);
Paankey56
  • 105
  • 1
  • 7
  • You have some syntax errors on that snippet. You have a floating '}' and missing closing the function ending bracket. – MarkSkayff Dec 03 '19 at 19:34
  • This doesn't seem to be about function parameters at all but about inserting variables into a string. You can use basic concatenation or template literals for that. When looking for existing solutions while doing research, it is important not to get distracted by too much context; most programming issues are actually a bunch of smaller ones which can be easily solved if tackled individually. –  Dec 03 '19 at 19:37
  • Does this answer your question? [How to interpolate variables in strings in JavaScript, without concatenation?](https://stackoverflow.com/questions/3304014/how-to-interpolate-variables-in-strings-in-javascript-without-concatenation) –  Dec 03 '19 at 19:39

1 Answers1

1
ellipse.setAttribute('d', `M 400 200 a ${polRad},${eqRad} 90 1,0 1,0 z`);

This should work except for older browsers : )

Chris Chen
  • 1,228
  • 9
  • 14