The second version of the pizza exercise was about changing the formula. It was only a bit of math. I was confused because my Math. functions weren't working right. But it had nothing to do with Math. It was all about my lack of a return keyword and some bad parens. I've become better at sussing those out - fewer initial assumptions on my part.
The math is a bit more difficult to work out mentally than the other pizza exercise. I almost had to write it down to make sure it was right. I didn't do the part with use "piece" or "pieces" depending on 0, 1, many. That seems like busywork.
[Image]
The Vue.js code:
HTML:
Number of People:
Slices Desired (each):
Number of Slices per Pizza:
Number of pizzas: {{pizzas}}
Leftover slices: {{slicesLeftover}}
VUE + Javascript:
var app = new Vue({
el: '#app',
components: {
},
data: {
people: 10,
slicesDesired: 5,
slices: 8
},
computed: {
pizzas: function(){
//return ((this.pizzas * this.slices) % this.people);
//the disadvantage of f-ed up long math in line, you lose your place, that took a few iterations
return Math.ceil((this.people * this.slicesDesired) / this.slices);
},
slicesLeftover: function(){
return (this.people * this.slicesDesired) % this.slices;
}
}
})
"Exercises for Programmers: 57 Challenges to Develop Your Coding Skills - Chapter 3, Pizza Slices, Version 2"
No comments yet. -