//How much pizza each party goer will recieve
const slices = 3; //Number of slices 8
var people = 8; //Number of people 25
var pizzas = 10; //Number of pizzas 10
//pizzas ordered times the number of slices, divided by the number of people & asign slicePerson variable
var slicePerson = (slices * pizzas)/people;
//print out how many pieces per person
console.log("Each person ate" + " " + slicePerson + " " + "slices of pizza at the party.")
//Sparky gets what remainder of pizza
//Slices by pizzas used modulo to give remainder with people
var dogFood = 30 % people;
//print out how many slices sparky got
console.log("Sparky got" + " " + dogFood + " " + "slices of pizza.");问题是:
在披萨派对上,主人的狗很兴奋,因为在披萨片被平均分配给客人之后,主人的狗就会得到剩下的披萨。假设客人得到一整片,Sparky会享用多少整片?示例数据集: 10个人,4个披萨,每个披萨8片,这意味着每个人吃3片,Sparky得到2片。(请注意,这只是一个示例,无论我为这些给定的变量输入多少数字,您的代码都应该可以工作,并给出准确的结果。)给定:不要为此创建新的给定变量/常量。取而代之的是,使用您为Slice of Pie I设置的给定函数。结果变量: Sparky可以吃到的切片数量。打印结果:“Sparky得到了X片披萨。”
我已经插入并尝试了尽可能多的方法,但我可以让它与不同的数字一起工作。它总是会有一点点的偏差。
发布于 2013-11-06 04:57:46
var leftovers = (slicesPerPizza * numberOfPizzas) % numberOfGuests;
var slicesPerPerson = (slicesPerPizza * numberOfPizzas - leftovers) / numberOfGuests;每个客人都有slicesPerPerson,而Sparky得到剩菜。
https://stackoverflow.com/questions/19798480
复制相似问题