Uncaught Referenceerror: myFunction is not defined

Asked

Viewed 306 times

-2

I need a JS application to which I should compare 2 Ips .

Initial numbers must be equal but the end of 1 IP must always be greater than the second
Example:

10.200.1.6 > 10.200.1.2 = true

My code:

var rangeInicio = '10.200.1.6';
var splits = rangeInicio.split('.', 4);
console.log(splits);
var rangeFim = '10.200.1.2';
var splits = rangeFim.split('.', 4);
console.log(splits);


function myFunction() {
    var rangeInicio = "10.200.1.6";
    var rangefim = "10.200.1.2";
    var n = rangeInicio.localeCompare(rangeFim);
    document.getElementById("demo").innerHTML = n;
}

$(document).ready(function("demo") {

  $("#more").click(function ("demo") { 
  • It would be nice to put more information and code that is using

  • 2

    You want someone to make this application for you?

  • @Click [Dit] and format your question. You can’t understand anything with these loose comments.

  • Edited commentary

  • Related https://answall.com/questions/88463/problemas-com-uncaught-referenceerror-is-not-defined

1 answer

1

I suppose these ips are in string format, and that’s only the last parameter that changes you can take the dots and treat as a number:

function compararIps(a, b) {
  a = Number(a.replace(/\./g, ''));
  b = Number(b.replace(/\./g, ''));
  return a > b;
}

var rangeInicio = '10.200.1.6';
var rangeFim = '10.200.1.2';
console.log(compararIps(rangeInicio, rangeFim));

  • 1

    is that Rgio mt thank you <3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.