hi everyone so i’m solving the problem i have a script
this is the result from the web
JavaScript
x
2
1
1/5
2
how to split into two separate numbers?
the output is this how to do not let go if the number is greater than 5?
these are different numbers, for example:
JavaScript
1
3
1
1/4
2
2/4
3
They need that the second numbers is not greater than 5
JavaScript
1
2
1
let maxPopulation = document.querySelector("#content_value > table:nth-child(2) > tbody > tr > td:nth-child(2) > table:nth-child(1) > tbody > tr:nth-child(2) > td:nth-child(5)").innerText
2
normal code would be done like this
but the sign prevents me from doing that
JavaScript
1
2
1
if ((maxPopulation)> = 5)
2
the problem, however, makes me a sign / I don’t know how to separate the two numbers and if the second one is bigger than 5 so that the script doesn’t continue to work
Advertisement
Answer
You can use split function:
JavaScript
1
6
1
result = '1/5';
2
let splitted = result.split('/');
3
if(splitted[1]>=5)
4
DoSomething();
5
6
split returns an array, so second part is at position [1]
Update 1:
According to your comments you need specifically this:
JavaScript
1
11
11
1
const fieldValues = document.querySelector("#content_value > table:nth-child(2) > tbody > tr > td:nth-child(2) > table:nth-child(1) > tbody > tr:nth-child(2) > td:nth-child(5)").innerText
2
3
const splitted = fieldValues.split('/');
4
5
if(parseInt(splitted[1])>=5){
6
// your code for equal or greater than 5
7
}
8
else{
9
// your code for < 5
10
}
11