LocalStorage, Loops and Arrays

Week 10 turned out to be a better week then last. I paced myself as I worked and forced myself not to do any work for longer than four hours straight. I’d take a rest and start again with my mind refreshed and my body reinvigorated.

Our App

We all were able to make it to this week’s meeting. They both had code to show, as did I, but my code didn’t work. I wanted to setup an login/registration page using XML and AJAX, without using MySQL. I will be learning that next semester, so I was pulling my hair trying to find a website that had what I wanted to know on it. 🙂 In the end I just used local storage.

Local Storage

My code is pretty straightforward

*************************************************************
JavaScript
function register() {
// Get elements
var uname = document.getElementById(“username”).value;
var pword = document.getElementById(“password”).value;

// Check
if (typeof(Storage) !== “undefined”) {
// store user defined text
localStorage.username = uname;
localStorage.password = pword;
document.getElementById(“loginMessage”).innerHTML = “Your new account has been activated.”;
} else {
var cookieEnabled=(navigator.cookieEnabled)? true : false;
if (typeof navigator.cookieEnabled===cookieEnabled){
document.cookie = “username=uname; password=pword; expires=Thu, 31 Dec 2015 12:00:00 UTC”;
document.getElementById(“loginMessage”).innerHTML = “Your new account has been activated.”;
} else {
document.getElementById(“loginMessage”).innerHTML = “Your new account cannot be created until you turn cookies on.”;
return;
}

}
}

function loginTest() {
// Get elements
var uname = document.getElementById(“username”).value;
var pword = document.getElementById(“password”).value;

// Check
if (typeof(Storage) != “undefined”) {
// store user defined text
var password = localStorage.getItem(“password”);
var username = localStorage.getItem(“username”);

if (username === uname && password === pword){
window.open(“website address here”);
} else {
document.getElementById(“loginMessage”).innerHTML = “Your password or username are not correct. Try again.”;
return;
}
} else {
var username = document.cookie.username;
var password = document.cookie.password;

if (username === uname && password === pword){
window.open(“website address here”);
} else {
document.getElementById(“loginMessage”).innerHTML = “Your password or username are not correct. Try again.”;
return;
}

}
document.getElementById(“firstDisplay”).innerHTML = output;

}

*************************************************************
I have two functions, one to register the user and one to test to see if the entered username/password combo are correct when they register. There is no point in using this for a real app. It’s not secure in the least. You’ll see that I first test to see if local storage is available on the users computer. If not I try to store the data as cookie. If this doesn’t work, the user is told to turn on cookies. It’s simple. Perhaps when I know how to use MySQL I’ll revisit this project and fix it, just so I know how it works.

Loops and Arrays

I worked up some sandbox code demonstrating that I knew how to use Loops and Arrays, but there wasn’t a submission box to submit my code this week. Unfortunately, I had already submitted the lesson submission box. So I’m out of luck. I did it to meet one of the requirements of the rubric.

Conclusion

I’m glad the week is over. We still need to add AJAX into the mix on our app. No idea how we’ll do it or what my next assignment will be. Only the future will tell.

Animation and Local Storage in HTML

This week we continued on with learning the nine topics we need to know about to write our team app.

Sharing Video

First up this week we needed to share the sandbox code we came up with for the new areas our teammates created last week. I did some HTML Animation and JavaScript Object code snippets so I made a video sharing work with my team. I used Corel Screen Capture to make the video, instead of Google+, and I love it! I just got the program. It looks like the entire suite of three program will be a great benefit.

Our Meeting

This week’s meeting didn’t go so well. One of our members didn’t show. After waiting for 30 minutes we started the video. My teamate redid the topic he did last week and added some information on Local Storage, but he had no code. I added a few words and showed my code on local storage. It was a bit frustrating, but we got it done.

Conclusions

This was a very hectic week. I couldn’t even get started with my work until Thursday. In the end, I got it all done. It was a joy to spend all my school time on Friday on the class. Programming is fun.