4 Replies - 283 Views - Last Post: 07 July 2019 - 10:40 PM

#1 Danielle210   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-July 16

please i need your help with javascript

Posted 07 March 2018 - 04:22 AM

I want to add the functionality of subtraction, multiplication, and division, how will I go about it:
here's my code:
function randomNum() {
    var num1 = document.getElementById("num1");
    var num2 = document.getElementById("num2");
    num1.innerHTML = Math.floor(Math.random()*50+1);
    num2.innerHTML = Math.floor(Math.random()*50+1);
}

function checkMath() {
    var num1 = parseInt(document.getElementById("num1").innerHTML, 10);
    var num2 = parseInt(document.getElementById("num2").innerHTML, 10);
    var answer = parseInt(document.getElementById("answer").value, 10);
    if (answer === num1 + num2) {
        alert("your answer is correct");
    } else {
        alert(answer + " is incorrect, correct answer is " + (num1+ num2));
    }
    document.getElementById("answer").value="";
    randomNum();
}




Is This A Good Question/Topic? 0
  • +

Replies To: please i need your help with javascript

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4230
  • View blog
  • Posts: 13,409
  • Joined: 08-June 10

Re: please i need your help with javascript

Posted 07 March 2018 - 04:47 AM

Are there any problems?
Was This Post Helpful? 0
  • +
  • -

#3 Danielle210   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-July 16

Re: please i need your help with javascript

Posted 07 March 2018 - 06:18 AM

I want to add the functionalities of subtraction division and multiplication

This post has been edited by Dormilich: 07 March 2018 - 06:24 AM

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4230
  • View blog
  • Posts: 13,409
  • Joined: 08-June 10

Re: please i need your help with javascript

Posted 07 March 2018 - 06:26 AM

Then you only have to change the operator on line #12. Be aware though that this is floating point math.
Was This Post Helpful? 0
  • +
  • -

#5 sagar.chavada   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 10-April 19

Re: please i need your help with javascript

Posted 07 July 2019 - 10:40 PM

My point of view you have to create two more condition in your code if you did not create you have to use switch case condition for your code
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1