Posts: 5,945
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
|
If this is homework, as I suspect it is (no real-world application would be this poorly designed and useless, nor would it use Javascript), I'm not going to give you the full answer. But I will tell you this:
getNextVote will give you the value (0, 1, 2, 3) of the leftmost number in that string full of garbage you posted here:
01132310331013322132332221330330212003102332032010 13201120030202030221202020232122211330303122021100 3
getRemainingVotes will remove the first vote from the string and spit out all the remaining ones at the time.
So the rough idea that you want is:
get the next vote
assign it to a variable corresponding with whoever was voted for
get the remaining votes
repeat 1-3 until the allVotes string is down to 1 vote (you won't be able to get the remaining votes because your substring will be 0 in length).
Print out the results
Show which candidate won
Count number of votes
That should get you started.
|