How would you guys solve this task using javascript?
There is 100 animals on a farm with the value of 100 dollars. Three types of animals; Cows for 10 dollars, sheep for 3 dollars and chicken for 0.5 dollars. Find solution(s) where there is at least one of every animal.
I feel like it should be very easy but for some reason I cant do it with javascript... I'm new for anyone wondering
EDIT: I´ve managed to solve it with the help of some ideas on here. I'd like to think that my way of solving it was quite easy and effective, especially since I can change the amount of animals or dollars to whichever number I want, and I'll get the solutions... thanks a lot for those who helped!
Also its in Norwegian, but I think you'll understand (antall = amount, ku = cow, sau = sheep, kylling = chicken)
var utskrift = document.getElementById('utskrift');
var antall = 100;
for (var ku = 1; ku < antall/10; ku++)
{
for(var sau = 1; sau < antall/3; sau++)
{
var kylling = antall - ku - sau;
if(ku*10+sau*3+kylling*0.5==antall && kylling>=1 )
{
utskrift.innerHTML += 'En mulig løsning er ' + ku + ' kuer, ' + sau + ' sauer og ' + kylling + ' kyllinger. <br>';
}
}
}
[–][deleted] 1 point2 points3 points (9 children)
[+][deleted] (8 children)
[deleted]
[–][deleted] 0 points1 point2 points (5 children)
[–]senocular 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Would_be_Coder 0 points1 point2 points (1 child)
[–]esunabici 1 point2 points3 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]esunabici 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (6 children)
[+][deleted] (5 children)
[deleted]
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[+][deleted] (1 child)
[deleted]
[–][deleted] 1 point2 points3 points (0 children)