This is the P2PU Archive. If you want the current site, go to www.p2pu.org!

Javascript: 101

My recent threads

You haven't posted any discussions yet.

Recently updated threads

Prerequisit Tasks 1 and 2

Go back to: General discussion

Here is my blog post on task 1 and 2. Please let me know if I need to post this elsewhere.

http://ryan-wells.blogspot.com/2011/01/javascript-basics-1-video.html

RW

Glenn Hellquist's picture
Glenn Hellquist
Tue, 2011-01-11 16:18

Since we are all here to learn I must ask. Why did you use the parseInt() function to get the value within the "quotemarks", instead of just asign the value to the variable, like t=2 without quotemarks and then put it together without parseInt()?

does it give some sort of benefit doing that way?

John Clifford Taylor's picture
John Clifford Taylor
Tue, 2011-01-11 17:04

I did it that way 2, the reason that I went that rough is because its AS3 convention to wrap vars in single quotes;

AS3 Code example:

var helloTxt:string = 'Hello world!';

Is that not necessary in JavaScript?

Glenn Hellquist's picture
Glenn Hellquist
Tue, 2011-01-11 16:55

we will probably learn about that in the course. But I think that the quotemarks is for text.

http://www.w3schools.com/js/js_variables.asp

they use the example:

var x=5;
var carname="Volvo";

I did mine real simple:

a=2;
b=2;
c=a+b;
alert(c)

and that worked well :)

then I did it your way and both work well :)

Jakub Pocentek's picture
Jakub Pocentek
Wed, 2011-01-12 01:49

You can put it even simpler:

alert(2+2)

Quotemarks are for strings, so

alert("2"+"2")

same as:

alert('2'+'2')

will produce 22. Using ParseInt is good when you take values from user input. I think that's common practice to use ParseInt with mathematics in JavaScript to avoid string concatenate.

Victor M's picture
Victor M
Wed, 2011-01-12 05:43

Or use alert(+'2' + (+'2')); :)

Ryan  Wells's picture
Ryan Wells
Thu, 2011-01-13 19:24

Great explanation, Jakub.

John Clifford Taylor's picture
John Clifford Taylor
Wed, 2011-01-12 03:56

Oooo your good Jakub!

ozzie sutcliffe's picture
ozzie sutcliffe
Wed, 2011-01-12 08:59

http://itsmartisans.com/javascript_class_intro/
I found 4 ways and I am sure there other variants also.
Will do the video tomorrow
http://www.plus2net.com/html_tutorial/tags-page.php these folks had a nifty page convert html code in a page.
That saved me a bit of brain-busting

oz

Jason Nyquist's picture
Jason Nyquist
Wed, 2011-01-12 13:18

I used +"1" + +('1'), parseint(), and Number() - just because I could - they were aspects of the JavaScript Basics 1 video.
Of course the simplest method works just swell, but "knowing is half the battle"... and funner

Parag Shah's picture
Parag Shah
Wed, 2011-01-12 15:34

Sure, it's wonderful to explore different ways of doing things while learning. That way we can make an informed choice about the best way to do something when writing production code.

I agree "knowing is half the battle"

Blain Armstrong's picture
Blain Armstrong
Wed, 2011-01-12 16:50

I also think it's important to remember this old tidbit: There's more than one way to skin a cat. ;)

Jakub Pocentek's picture
Jakub Pocentek
Wed, 2011-01-12 17:10

But always remember about Okham's Razor: The best solution is the simplest solution ;) Simpler program is faster.

stephen dixon's picture
stephen dixon
Thu, 2011-01-13 16:15

Not quite: Occam's razor actually says the explanation that involves the fewest assumptions is usually better. That's usually, but definitely not always the simplest.

BTW hello everyone, here's my blog: http://stib.posterous.com/
and exercise: http://pureandapplied.com.au/p2pu/2plus2.html

I did it using the newly acquired insight into the way the + operator means two different things depending on the type of the variable: alert("2 + 2 = " + (2+2)) The middle "+" sign concatenates the first string with the result of the sum - turning it into a string, the last one adds the two numbers (that's why they're in parentheses so that the addition happens before the concatenation, otherwise it would have resulted in "2 + 2 = 22").

Jakub Pocentek's picture
Jakub Pocentek
Thu, 2011-01-13 17:47

That's definitely true, you got me;) But I think that in the case of real application, when you have to think about security, user input etc., this definition will be even more accurate.

Maya Incaand's picture
Maya Incaand
Wed, 2011-01-12 17:34

I didn't know we are supposed to put them here as well:

http://mayinc.madpage.com/SignUp.html
http://umustbe.wordpress.com/javascript-signup/

Parag Shah's picture
Parag Shah
Wed, 2011-01-12 18:48

Just something I wanted to share.

As Blain said, there are multiple ways of solving a problem. This is something we come across very often in programming.

A certain approach has helped me:
1. While learning, try to do things in different ways, exploring even what may not be considered good solutions.

2. While writing production code, the simplest approach is usually the best approach. Code readability almost always trumps clever but obscure coding.

Along with learning Javascript I am hoping to discuss coding best practices also.

dysert's picture
dysert
Thu, 2011-01-13 14:03

>>While writing production code, the simplest approach is usually the best approach. Code readability almost always trumps clever but obscure coding.

This is true. One thing that has stuck with me from my computer science courses is that most of the cost of software is incurred in the maintenance phase. So anything you can do as a programmer to make your code easier to understand (and therefore easier to maintain) is a good thing. This of course includes adding comments to your code where necessary.

Nick's picture
Nick
Thu, 2011-01-13 05:53

Parag,
I'm glad to see you write that.

Roughly 15 years ago I learned C and C++. Once I finally started to wrap my brain around the concept of how software works I discovered a universe of conversation about how to optimize the code you write. Some of the best code examples I came across could have been described as "elegant". For me this took software programming from being a mere craft (albeit cool and highly technical) to being a kind of art.

Looking forward to this course,
n

Jakub Pocentek's picture
Jakub Pocentek
Thu, 2011-01-13 19:56

I agree that progamming is kind of art. I've learned some JavaScript and PHP before and found that you can read books and watch videos and you will learn the language syntax, but with programming languages, like with human ones, you have many ways to do something. Great skill is to "tell" computer to do something really "cool", so you have to be creative. Knowledge is not everything.

I'm happy to see more people thinking like that. I hope we will have opportunity to share our thoughts.

Melipone Moody's picture
Melipone Moody
Thu, 2011-01-13 06:08

Where are we supposed to post our blog notes and programming assignments? Here?

Ajit Ambekar's picture
Ajit Ambekar
Thu, 2011-01-13 08:52

I posted it in the space just below where they have asked us to do the assignment...

Jorge Encarnação's picture
Jorge Encarnação
Thu, 2011-01-13 13:26

I'm also confused on that one.

roland wettstein's picture
roland wettstein
Fri, 2011-01-14 08:25

I have submitted task1 during the application procedure in the form supplied.
In jumped the gun and submitted the application before pasting my blog's address onto it. So here is the Url

http://swissrunner.blogspot.com/2011/01/javascript-101-blog-info.html

Roland

Mihaela Tamasan's picture
Mihaela Tamasan
Sun, 2011-01-16 05:42

Hi,

Here is my blog post on task 1 and 2 from Prerequisites:
http://mtamasan-p2pu-jsbasics1.blogspot.com/2011/01/notes-about-javascri...

MT

Terupe Salmon's picture
Terupe Salmon
Sun, 2011-01-16 09:25

Hi,

Here is my blog post for task 1 and task 2 :

http://javascript101-terupe.blogspot.com/

Kai Vong's picture
Kai Vong
Sun, 2011-01-16 14:03

I sent all my notes in a post on here... and will look later if I can grab them to update my blog post with all my learnings from the Douglas Crockford talk. Great choice to start off with...

Here is my blog post: http://kaivong.com/2011/01/p2pu-webcraft-course-javascript-101/

Looking forward to learning lots in this journey and hearing from lots of you in the future :)

Garrett N's picture
Garrett N
Wed, 2011-01-19 06:13

Pre-requisite tasks 1 and 2 have been completed and are online at http://p2pu.tumblr.com/

Georges Duplessy's picture
Georges Duplessy
Wed, 2011-01-19 06:46

Garret, make sure to click "Apply" and put the link there

Michelle Flinchbaugh's picture
Michelle Flinchbaugh
Wed, 2011-01-19 12:49

My blog and the assignment are linked from this web page: http://us
erpages.umbc.edu/~flinchba/JavascriptPractice.html
. After I did the
assignment I tried some of the other ways that people did it too so that's
posted there too.

Louis Kwong's picture
Louis Kwong
Wed, 2011-01-19 14:48

Thanks for accepting me to the course. Here is my blog with the pre-entrance assignments.
http://koldo-p2pu-javascript101.blogspot.com/

It is really good to see so many different methods used to the same job.

Adam Floater's picture
Adam Floater
Wed, 2011-01-19 15:41

Hi All,

Just trying to start the pre-entrance assignments but can't get the video at http://www.diycomputerscience.com/courses/course/JAVASCRIPT/competency/185 to work. Is it just me and my lovely work connection?

Jorge Encarnação's picture
Jorge Encarnação
Wed, 2011-01-19 15:52

Seems to be working for me mate. Try here: http://video.yahoo.com/watch/111593/1710507 , shouldn't be any different but worth the try.

Jenny Stanchak's picture
Jenny Stanchak
Thu, 2011-01-20 04:21

I guess we're all linking our assignments here. Task 1 and 2 are on my javascript blog. http://jennysjavascript101.blogspot.com/

Adam Floater's picture
Adam Floater
Thu, 2011-01-20 10:26

Thanks Jorge, your link is blocked at work. Time for some home work, thanks for the help!

David Morales's picture
David Morales
Thu, 2011-01-20 17:53

Hello everyone!
Here are my impressions about the video aka task 1
iwannabejavascripter.wordpress.com
And my code for 2+2: http://jsfiddle.net/coper/GyHyX/

Maya Incaand's picture
Maya Incaand
Sat, 2011-01-22 16:27

Hi David

that jsfiddle site seems quite interesting, I'll have a play with that....

Ivan Teoh's picture
Ivan Teoh
Thu, 2011-01-20 23:57

Ops I put the link at the other forum. I guess this is the right place.
Here is my sign up task post including the code for the task 2 too.
http://www.ivanteoh.com/blog/2011/01/javascript-101-sign-up/

Maya Incaand's picture
Maya Incaand
Sat, 2011-01-22 15:50

"Write a simple Javascript program which will print the sum of 2+2 and display the result in an alert window in the browser."

I understood this as:

1) Print the sum of 2+2 in the browser AND
2) Display the result in an alert box

not just 2)....

Todd List's picture
Todd List
Tue, 2011-01-25 00:44

Hi all, I finally set up a blog to document my course experiences. The homework for the application is up: http://tjlist.net/2011/01/hello-p2pu/

I look forward to interacting with everybody more.