Question on Program that accept two integers and display the larger.

Report
Question

Please briefly explain why you feel this question should be reported .

Report
Cancel

Hi, I really new to javascript. I was doing a JavaScript program that accept two integers and display the larger.

Below is the program, It only displays the 2nd number. Can you tell me what i am doing wrong in this please?????

var x = prompt("Enter 1st number");
var y = prompt ("Enter 2nd number");

if(x>y){

  alert(x);
}

else {
alert(y);
}

I will really appreciate your help and this helps me to learn more..

closed 0
JavaScript 3 months 1 Answer 319 views 1

About naasir

Answer ( 1 )

  1. rg123

    Please briefly explain why you feel this answer should be reported .

    Report
    Cancel

    Please check the following link
    http://www.w3resource.com/javascript-exercises/javascript-conditional-statements-and-loops-exercise-1.php
    Code :
    var num1, num2;
    num1 = window.prompt(“Input the First integer”, “0”);
    num2 = window.prompt(“Input the second integer”, “0”);

    if(parseInt(num1, 10) > parseInt(num2, 10))
    {
    console.log(“The larger of “+ num1+ ” and “+ num2+ ” is “+ num1+ “.”);
    }
    else
    if(parseInt(num2, 10) > parseInt(num1, 10))
    {
    console.log(“The larger of “+ num1+” and “+ num2+ ” is “+ num2+ “.”);
    }
    else
    {
    console.log(“The values “+ num1+ ” and “+num2+ ” are equal.”);
    }

Leave an answer