我试图让这个功能在javascript中正常工作,它工作正常我可以发生的是底部console.log(工作(“从地毯上提取了加仑的水。”));我无法得到“从地毯中提取了加仑的水”。显示在同一行代码中。
// Global variable
var waterGallons = 40
var work = function(total) {
var water = 0;
while (water < waterGallons) {
console.log("The carpet company was called out to extract " + water + " gallons of water.")
water+=4;
};
return waterGallons;
}
console.log (work(" gallons of water has been extracted from the carpet."));
所以使用我得到帮助的答案就是我想出来的,因为我需要使用一个全局变量。所以我的故事将通过改变全局变量而改变。
var total = 40
var work = function(total) {
var water = 0;
while (water < total) {
console.log("The carpet company was called out to extract " + water + " gallons of water.")
water+=4;
};
return water;
}
console.log (work(total) + " gallons of water has been extracted from the carpet.");
我想再次感谢你们。我还有一个布尔函数,一个使用 for 循环函数的数组,还有一个过程。所以使用这个我应该能够理解如何创建我的作业的下一部分。