Bus blockchain program

I assume have made a simple math error somewhere given it does what I want, but the numbers for stop 2 and 3 are wrong

var passenger=0;

var passenger1=prompt(“How many passengers get on bus at stop1?”);

if(passenger1>30){console.log(“There are too many passengers on the bus, this many people will have to walk:”+ (passenger1-30));} else{console.log(“The bus isnt full, it shall now proceed to station 2”);}

var passenger2= (passenger+passenger1);

var bus2=prompt(“How many passengers get on bus at stop2?”);

if((passenger2 + bus2)>30){console.log(“There are too many passengers on the bus, this many people have to walk:”+ ((passenger2 + bus2)-30));} else{console.log(“The bus isnt full, it shall now proceed to station 3”);}

var passenger3= (passenger2+bus2);

var bus3=prompt(“How many passengers get on bus at stop3?”);

if((passenger3 + bus3)>30){console.log(“There are too many passengers on the bus, this many people have to walk:”+ ((passenger3 + bus3)-30));} else{console.log(“The bus isnt full, it shall now proceed to station 3”);}

this is the bus question, 24 i think

Hi @lhayward23

The data that you get back with prompt() is not an integer but a string.
When you are in doubt and you get strange results from your code, you can always console.log the results and inspect them :slight_smile:

Check my example for you below.

image

It might be a good idea to console.log your data and convert the strings to numbers before doing operations with them.

Happy learning,
Dani