Open Danbaba1 opened 2 years ago
@Danbaba1 I've seen my error with the switch statement while we were taking a look at the exercise together earlier. It was supposed to be case "small":
and not case lime === "small":
. I told you it must be one silly mistake I must have been making - and there it is. Also, just like I said using a while or do-while loop doesn't work here.
function limesToCut(numberOfLineWedges, supplyOfWholeLimesArray) {
let addUpWedgesFromArray = 0;
let numberOfLimes = 0;
supplyOfWholeLimesArray.forEach((lime, index) => {
let amountOfWedgesFromLime = 0;
switch(lime) {
case "small":
amountOfWedgesFromLime = 6;
break;
case "medium":
amountOfWedgesFromLime = 8;
break;
case "large":
amountOfWedgesFromLime = 10;
break;
}
if (addUpWedgesFromArray < numberOfLineWedges) {
addUpWedgesFromArray += amountOfWedgesFromLime;
numberOfLimes = index + 1;
}
});
return numberOfLimes;
}
limesToCut(25, ['small', 'small', 'medium', 'large', 'small']);
@Ifycode it worked in the exercism editor. but is there a way i can use a while loop and switch statement
@Ifycode what about the third function in exercise 9
Well, there are two things I will say concerning this.
But I could try again to see if a do-while or while loop would work. But definitely not with forEach, because it gives a wrong answer.
@Ifycode it worked in the exercism editor. but is there a way i can use a while loop and switch statement
@Ifycode what about the third function in exercise 9
Ok, I was thinking that you said it's the 2nd function you are having problems with. So I didn't attempt that.
So try it out if you haven't. If you don't get it by tomorrow morning or noon, do this.
9.js
, then copy and paste everything you have on your exercism editor in there. i was able to use a while loop with the second function on mixed juices exercise.
function limesToCut(wedgesNeeded,limes){ let limeCut = 0; let wedgeCut = 0; let index = 0; let numLimes = 0; while(index < limes.length){ switch(limes[index]){ case 'small': wedgeCut = 6; break; case 'medium': wedgeCut = 8; break; case 'large': wedgeCut = 10; break; } if(limeCut < wedgesNeeded){ limeCut += wedgeCut; numLimes += 1; } index += 1; } return numLimes; } console.log(limesToCut(0,['small','small','large','medium','small']));
i was able to use a while loop with the second function on mixed juices exercise.
function limesToCut(wedgesNeeded,limes){ let limeCut = 0; let wedgeCut = 0; let index = 0; let numLimes = 0; while(index < limes.length){ switch(limes[index]){ case 'small': wedgeCut = 6; break; case 'medium': wedgeCut = 8; break; case 'large': wedgeCut = 10; break; } if(limeCut < wedgesNeeded){ limeCut += wedgeCut; numLimes += 1; } index += 1; } return numLimes; } console.log(limesToCut(0,['small','small','large','medium','small']));
Nice work, well done @Danbaba1 I have written a reply to the comment on the PR for function 3. Pasting your code will give me a better idea of what you are struggling with.
@Ifycode thank you so much
Exercise: Mixed Juices
issue: .I am unable to use while loop and switch statement to run the code. . Also I am unable to come up with an algorithm to solve the code.
Where: function 2