0% found this document useful (0 votes)
3 views

APCSP Program Code

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

APCSP Program Code

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

//all the teams that can be picked

var top_ten = ["Bayern Munich", "Real Madrid", "Liverpool" , "Manchester City", "Chelsea",
"Villareal", "Benfica", "Atletico Madrid"];
// the counter for all the teams based on wins
var team_1 = 0;
var team_2 = 0;
var team_3 = 0;
var team_4 = 0;
//to go to the main page
onEvent("button1", "click", function( ) {
setScreen("screen2");
});
//to call the function for the first time
onEvent("button2", "click", function( ) {
setText("text_area14", func(getText("team1"), getText("team2")));
setText("text_area5", (getText("team1") + " VS ") + getText("team2") );
});
//to call the function another time using different teams
onEvent("button3", "click", function( ) {
setText("text_area13", func(getText("team3"), getText("team4")));
setText("text_area6", (getText("team3") + " VS ") + getText("team4") );
});
//function to give the scores and update the counter
function func(team1, team2) {
var score1 = 0;
var score2 = 0;
var win;
for (var i = 0; i < top_ten.length; i++) {
if (top_ten.indexOf(team1) < 5) {
score1 = randomNumber(1,4);
} else if ((top_ten.indexOf(team1) >= 5)) {
score1 = randomNumber(0,3);
}
if (top_ten.indexOf(team2) < 5) {
score2 = randomNumber(1,4);
} else if ((top_ten.indexOf(team2) >= 5)) {
score2 = randomNumber(0,3);
}
}
if (score1 == score2 && (team1 == "Real Madrid" || team1 == "Benfica")) {
team_1 = team_1 + 1;
team_2 = team_2 + 1;
win = (((((((("Hi "+getText("text_input1"))+"!") + (" The result for this match is: "+ team1)+ " "
+ score1) + " - ") + team2)+ " ")+ score2) + "...") + "It's a draw!" ;
setText("text_area3", team_1);
setText("text_area7", team_2);
} else if ((score1 > score2 && (team1 == "Real Madrid" || team1 == "Benfica"))) {
team_1 = team_1 + 1;
win = ((((((((("Hi "+getText("text_input1"))+"!") + (" The result for this match is: "+ team1)+ " "
+ score1) + " - ") + team2)+ " ")+ score2) + "...") + team1) + " wins!";
setText("text_area3", team_1);
setText("text_area7", team_2);
} else if ((score2 > score1 && (team2 == "Ateltico Madrid" || "Liverpool" == "Liverpool"))) {
team_2 = team_2 + 1;
win = ((((((((("Hi "+getText("text_input1"))+"!") + (" The result for this match is: "+ team1)+ " "
+ score1) + " - ") + team2)+ " ")+ score2) + "...") + team2) + " wins!" ;
setText("text_area3", team_1);
setText("text_area7", team_2);
}

if (score1 == score2 && (team1 == "Chelsea" || team1 == "Manchester City")) {


team_3 = team_3 + 1;
team_4 = team_4 + 1;
win = (((((((("Hi "+getText("text_input1"))+"!") + (" The result for this match is: "+ team1)+ " "
+ score1) + " - ") + team2)+ " ")+ score2) + "...") + "It's a draw!" ;
setText("text_area11", team_3);
setText("text_area12", team_4);
} else if ((score1 > score2 && (team1 == "Chelsea" || team1 == "Manchester City"))) {
team_3 = team_3 + 1;
win = ((((((((("Hi "+getText("text_input1"))+"!") + (" The result for this match is: "+ team1)+ " "
+ score1) + " - ") + team2)+ " ")+ score2) + "...") + team1) + " wins!";
setText("text_area11", team_3);
setText("text_area12", team_4);
} else if ((score2 > score1 && (team2 == "Bayern Munich" || "Villareal" == team2))) {
team_4 = team_4 + 1;
win = ((((((((("Hi "+getText("text_input1"))+"!") + (" The result for this match is: "+ team1)+ " "
+ score1) + " - ") + team2)+ " ")+ score2) + "...") + team2) + " wins!" ;
setText("text_area11", team_3);
setText("text_area12", team_4);
}
return win;
}
//to change the counters to zero when a team changes
onEvent("team1", "change", function( ) {
team_1 = 0;
team_2 = 0;
});
onEvent("team2", "change", function( ) {
team_1 = 0;
team_2 = 0;
});
onEvent("team3", "change", function( ) {
team_3 = 0;
team_4 = 0;
});
onEvent("team4", "change", function( ) {
team_3 = 0;
team_4 = 0;
});

You might also like