EXECUTED PROGRAM APP LAB
var currentIndex=0;
var contact1=[];
contact1.name="Naveen";
contact1.phone="9618300797";
contact1.birthday="1/1/20";
//contact1.imageURL="https://images.app.goo.gl/fTUgCM9YGh6X2hfL6";
var contacts=[];
appendItem(contacts,contact1);
showCurrentContacts();
//showCurrentContacts();
showCurrentContacts();{
setText("contactsInfo",contacts[currentIndex].name);
setText("contactsInfo",contacts[currentIndex].phone);
setText("contactsInfo",contacts[currentIndex].birthday);
//setText("ContactsInfo",contacts[currentIndex].name);
function showCurrentContacts() {
setText("contactsInfo",contacts[currentIndex].name);
var nameString="Name :" + contacts[currentIndex].name;
var phoneString="Phone :" + contacts[currentIndex].phone;
var birthdayString="Birthday :" + contacts[currentIndex].birthday;
setText("contactsInfo",nameString + '\n' + phoneString + '\n' + birthdayString);
//setText("contactsInfo",nameString,phoneString,birthdayString);
}
onEvent("viewContactsScreen","keydown", function() {
if (event.key=="left") {
currentIndex--;
currentIndex=wrap(currentIndex,0,contacts.length -1);
showCurrentContacts();
});
function wrap(val,low,high)
var output;
if (val < low)
output=high;
} else if (val > high) {
output=low;
else {
output=val;
return output;
onEvent("saveContactsBtn", "click", function( ) {
var newcontact=[];
newcontact.name=getText("nameInput");
newcontact.phone=getText("phoneInput");
newcontact.birthday=getText("birthdayInput");
appendItem(contacts,newcontact);
setText("nameInput", "");
setText("phoneInput", "");
setText("birthdayInput", "");
setScreen("viewContactsScreen");
onEvent("addContactsBtn","click", function() {
setScreen("addContactsScreen");
});
currentIndex=contacts.length-1;
showCurrentContacts();
onEvent("backBtn", "click", function( ) {
setScreen("viewContactsScreen");
});
});