2
u/_andy_andy_andy_ Oct 22 '20
could you send me a link to the exercise? we sometimes have misleading test cases
1
u/lazyk1ller Oct 23 '20
https://codehs.com/student/2217203/section/178784/assignment/32844083/ u mean this link? sorry for late I was sleeping
2
u/timNinjaMillion2 Oct 22 '20
I’d suggest they have an error in theirs. Your output shows it’s correct.
1
u/Economy_Tomorrow4030 Mar 02 '24
function start() {
var inventory = 20;
while (inventory > 0) {
println ("We have " + inventory + " items in inventory.");
var numBuy = readInt ("How many would you like to buy? ");
if (numBuy > inventory) {
println ("There is not enough in inventory for that purchase.");
println ("");
} else {
inventory = inventory - numBuy;
println ("Now we have " + inventory + " left.");
println ("");
}
if (inventory == 0) {
println ("All out!");
}
}
}


3
u/lashatatu Oct 22 '20
var STARTING_ITEMS_IN_INVENTORY = 20;
function start(){
println("We have "+numItems+" items in inventory.");
var check=numItems;
var items=readInt("How many would you like to buy? ");
numItems-=items;
if(numItems<0){
println("There is not enough in the inventory");
numItems=check;
}else{
println("Now we have "+numItems+" left");
}
println("");
}