Uploaded by jakejin2016

Untitled document

advertisement
AP CSP CPT Program Code
// Lists containing data for each note.
var notesTitle = [];
var notesDesc = [];
var notesCategories = [];
var numOfNotes;
// Function to delete all notes. Is used when "clear" button is clicked
function resetScreenNotes() {
for (var i = 0; i < notesTitle.length; i++) {
deleteElement("noteLabel"+i);
deleteElement("noteButton"+i);
}
}
// Create on event for a specific button based on index. The index is used as a parameter
function createOnEvent(i){
onEvent("noteButton"+i, "click", function( ) {
// Output is sent to the infoScreen which includes th notesTitle and notesDesc
setScreen("infoScreen");
setText("infoTitleOutput",notesTitle[i]);
setText("infoContentOutput",notesDesc[i]);
});
}
// Function used update the notes screen whenever a new notes is made.
// Pass in the number of notes as a parameter because that is how many times we want to loop
function setScreenNotes(numOfNotes){
// Example of Iteration. For loop is used to iterate and create every note.
for (var i = 0; i < numOfNotes; i++) {
textLabel("noteLabel"+i,notesTitle[i]);
setPosition("noteLabel"+i,10,65+30*i,280,25);
setProperty("noteLabel"+i,"font-family","Courier");
setProperty("noteLabel"+i,"font-size","15");
// Example of Selection. If statements are used to check the category of the note
// and set the screens background color to the corresponding color
if(notesCategories[i] == "History"){
setProperty("noteLabel"+i,"text-color",rgb(0,0,255,1));
}
else if(notesCategories[i] == "Math"){
setProperty("noteLabel"+i,"text-color",rgb(0,255,0,1));
}
else if(notesCategories[i] == "English"){
setProperty("noteLabel"+i,"text-color",rgb(255,0,0,1));
}
button("noteButton"+i,"View");
setPosition("noteButton"+i,195,65+30*i,100,28);
setProperty("noteButton"+i,"font-family","Courier");
setProperty("noteButton"+i,"font-size","15");
setProperty("noteButton"+i,"background-color","black");
// Calling my procedure createOnEvent() with the parameter i.
// The function is called for every note because of the for loop.
createOnEvent(i);
}}
onEvent("createButton", "click", function( ) {
if (notesTitle.length>=11){
console.log("Max number of notes reached.");
return;
}
setScreen("createScreen");
});
onEvent("submitFormButton", "click", function( ) {
resetScreenNotes();
// Input from the user is the noteTitleInput, noteContentInput, and colorDropdown text
appendItem(notesTitle, getText("noteTitleInput"));
appendItem(notesDesc, getText("noteContentInput"));
appendItem(notesCategories, getText("colorDropdown"));
setScreen("homeScreen");
numOfNotes = notesTitle.length;
setScreenNotes(numOfNotes);
});
// Delete all notes from homeScreen using resetScreenNotes
// and clear all lists containing all the data
onEvent("clearHomeButtom", "click", function( ) {
resetScreenNotes();
notesTitle = [];
notesDesc = [];
notesCategories = [];
});
// Back buttons for easier navigating
onEvent("backFromInfoButton", "click", function( ) {
setScreen("homeScreen");
});
onEvent("backFromCreateButton", "click", function( ) {
setScreen("homeScreen");
});
Download