Need a bit of help

So im trying my self out with html+css+javascript for the first time, and im wondering what am i doing wrong here, is there a better way to make something like this? When i click on button nothing changes when i change numbers of para1 and para2. This is only for testing and practicing…

The button calls myFunction, but myFunction expects arguments passed to it. The function that the button calls also only do what it’s told to do: return a string value. Nowhere in that function is it told to modify the contents of the <p> with the demo id.

You may want to try including two <input> elements for para1 and para2. Then instead of using onclick in HTML, set up a more sophisticated event listener in JS.

<input id="para1">
<input id="para2">
<button id="submit">Click</button>
document.getElementById('submit').addEventListener('click', function() {
  // the values from the page are strings by default, so conversion to number is needed
  const para1 = Number(document.getElementById('para1').value);
  const para2 = Number(document.getElementById('para2').value);

  // modify `demo` afterwards
  document.getElementById('demo').innerHTML = myFunction(para1, para2);
});

(tip: since you’re trying code on jsfiddle, you may want to share a link to that instead of a screenshot)

1 Like

Ok thanks, but how do i share a link from it?

Hit the Save (or Update) button at the top, then copy and paste the URL in your browser’s address bar.

1 Like