1, I want to create a js as a reminder when my unit_balance is lower than 20.
2, 1st What i do is get each of unit_balance then i write a function to do compare < 20
3, if true then show alert , if not just ignore the alert
4, the code still error because i put all my unit_balance all higher then 20 also gv me alert
5, can give me some idea to do this? Im not good in js.
6, Please helps me. thank you
<body onload="myFunction()">
<script>
var unit_balance = [
@foreach ($bike as $value)
['{{ $value->unit_balance }}']
@endforeach
];
function myFunction(){
if(unit_balance < 20, true){
alert("Some of unit left is less than 20. Please restock immediately!");
}
}
</script>
</div>
If you unit_balance is array then you need to filter the value and check the length of the array
<body onload="myFunction()">
<script>
var unit_balance = [
20, 30
];
function myFunction(){
var totalLessThan20 = unit_balance.filter(unit => unit <=20 );
if(totalLessThan20.length) {
alert("Some of unit left is less than 20. Please restock
immediately!");
}
}
</script>