Add / subtract / multiply / divide two variables in a string?

advertisements

I need to output for example "variable + variable" without just displaying the end result. This is probably extremely simple (hopefully), but I'm having trouble with this.

  var rand1=Math.floor(Math.random() * 21);
  var rand2=Math.floor(Math.random() * 21);
  var result= rand1+rand2;
  document.getElementById('id1').innerHTML = result;

This obviously just returns the result of the two numbers added up. I need a way for this to output in the element like: Random Number + Random Number = Answer.


The innerHTML's value can be expressed as rand1 + "+" + rand2 + "=" + result as shown below,

  var rand1=Math.floor(Math.random() * 21);
  var rand2=Math.floor(Math.random() * 21);
  var result= rand1+rand2;
  document.getElementById('id1').innerHTML = rand1 + "+" + rand2 + "=" + result;