0% found this document useful (0 votes)
11 views2 pages

Code

AP CSP Final example (please don't copy the exact code, instead, try to take inspiration from the example).

Uploaded by

pmdubagunta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Code

AP CSP Final example (please don't copy the exact code, instead, try to take inspiration from the example).

Uploaded by

pmdubagunta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

4/29/24, 9:19 PM bakerfranke.github.

io/codePrint/

var countryName = getColumn("Countries and Territories", "Country Name");


var countryGDPP = getColumn("Countries and Territories", "GDP Per Capita");
var countryInternetLevel = getColumn("Countries and Territories", "Percent Using Internet");
var countryusingrenewableEnergy = getColumn("Countries and Territories", "Percent Renewable Ener
var countryRegion = getColumn("Countries and Territories", "Region");
var countryPopulation = getColumn("Countries and Territories", "Population");
var countryUnemploymentRate = getColumn("Countries and Territories", "Unemployment");
var continent = ["South Asia","Europe and Central Asia", "Middle East and North Africa", "East A
var resultCountry = [];
var integerList = [];
var bestIncome;
var lowUnemp;
var lowPop;
onEvent("Result", "click", function(){
setText("resulttext", calculate(getNumber("Internet"),
getText("Region"),
getNumber("GDP"),
getNumber("UnemploymentRate"),
getNumber("Population"),
getNumber("RenewableEnergy")).join("\n"));
setting();
rank();
wbutton();
});
onEvent("randomexpression", "click", function(){
var newContinent = continent[randomNumber(1,7)];
setText("resulttext", calculate(randomNumber(0, 100),
newContinent, randomNumber(1000, 100000),
randomNumber(0, 100), randomNumber(0, 100),
randomNumber(5000000,2000000000),
randomNumber(0,100)).join("\n"));
setting();
rank();
wbutton();
});
onEvent("TryAgainscreen3","click",function(){
goBack();
});
onEvent("backscreen4","click",function(){
goBack();
});
function calculate( minInternet, GeoRegion, minGDP, maxUnemploymentRate, MaxPopulation,Minrenewa
// use the 6 parameters to filter out unwanted countries,
//and add the countries that meet the requirement to integerlist
for (var i = 0; i < 216; i++){
if (countryGDPP[i] >= minGDP &&
minInternet <= countryInternetLevel[i] &&
GeoRegion == countryRegion[i] &&
maxUnemploymentRate >= countryUnemploymentRate[i] &&
MaxPopulation >= countryPopulation [i] &&
Minrenewable <= countryusingrenewableEnergy[i]) {

appendItem(resultCountry, countryName[i]);

https://bakerfranke.github.io/codePrint/ 1/2
4/29/24, 9:19 PM bakerfranke.github.io/codePrint/
54
appendItem(integerList, i);
55
56
}
57
}
58
return resultCountry;
59
}
60
function setting(){
61
if (resultCountry.length > 0){
62
setScreen("screen2");
63
}
64
else if (resultCountry.length==0){
65
setScreen("screen3");
66
}
67
}
68
function rank(){
69
// we will traverse through different lists [resultCountry[i]] to figure out the best income, lo
70
bestIncome = 0;
71
lowUnemp = resultCountry[0];
72
lowPop = resultCountry[0];
73
for (var n = 0; n < resultCountry.length; n++){
74
if (bestIncome < countryGDPP[integerList[n]]){
75
bestIncome = countryGDPP[integerList[n]];
76
}
77
if (lowUnemp > countryUnemploymentRate[integerList[n]]){
78
lowUnemp = countryUnemploymentRate[integerList[n]];
79
}
80
if (lowPop > countryPopulation[integerList[n]]){
81
lowPop = countryPopulation[integerList[n]];
82
}
83
}
84
}
85
function wbutton (){
86
onEvent("BestIncome", "click", function(){
87
setScreen("screen4");
88
setText("screen4text", bestIncome);
89
});
90
onEvent("LowUnemp", "click", function(){
91
setScreen("screen4");
92
setText("screen4text",lowUnemp);
93
});
94
onEvent("LowPOP", "click", function(){
95
setScreen("screen4");
96
setText("screen4text", lowPop);
97
});
98
}function goBack (){
99
for (var a = 0; a < integerList.length;){
100
removeItem(integerList, integerList.length - 1);
101
removeItem(resultCountry, resultCountry.length - 1);
102
}
103
setScreen("screen1");
104
}

PDF document made with CodePrint using Prism

https://bakerfranke.github.io/codePrint/ 2/2

You might also like