Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
George Dinmore
518 PointsNeed Help! Massively Confused With Javascript And PHP!
I picked the PHP Programming track. And i am really interested in learning PHP and Javascript. I found HTML and CSS to be easy, and grasp it quite well.
Now, when the track moved over to Javascript beginners, i passed all the quizzes and tests well. However, still did not know what was going on. Then, PHP turned up, and i am not getting it at all.
I understood the copyright footer part and the DOCTYPE and wrap in PHP code, from there, i get completely confused as to what is going on. Not sure if i need it explaining a different way, or i simply do not understand it.
Maybe i need to change my track to wordpress or design, need help!
8 Answers
Michael Mangan
9,164 Pointsim not sure which part your having a problem with, but ill try to answer it. keep in mind that PHP is a server-side scripting language. it is process once per load of the page. unlike javascript which runs on the client side and can dynamically update content with out refreshing the page. are you having a problem with syntax or the concept of server-side languages
Richard Duncan
5,568 PointsWe won't mention node.js then ;)
Michael Mangan
9,164 Pointsnode.js is more related to running outside the browser. it does not replace a server-side scripting lanuguage. it is powerful though
George Dinmore
518 PointsI am on the PHP developement track. So it starts with the html and css - found that easy to grasp and understand. Then it goes onto the concept and beginning of understanding Javascript - basic concepts - thankfully, as did not understand one part of it. However, got all the quizzes right - strange. Then goes onto basic PHP understanding. And that threw me completely. The only part i understnad with PHP is <?php echo "Hello World!"; ?> - that is it.
George Dinmore
518 PointsPlease Richard! Don't! :)
Richard Duncan
5,568 PointsDon't worry about server and client side, as you can technically run JavaScript on a server these days.If you want a language for say UI design to manipulate the document object model (DOM) then choose js. jQuery basics would be a good start if you want to go down that route.
If you want to interact with the server or database directly and/or build a wordpress template then opt for PHP. Without getting into it too deeply your application will usually be a series of variables and functions that combine to offer the features you want.
If you're struggling after echo in PHP I would assume that is because you're not familiar with programming and while you have made your way swiftly through HTML & CSS these are both not technically programming languages. HTML allows you to define the document structure, CSS uses selectors to tell the browser how to render that structure.
With programming you are looking to do a little bit more you will come across conditional statements the most common of which universally is an if ..else statement. This is an example of a logical construct or a condition which exhibits behaviour depending on what conditions are met.
Let's say in PHP you wanted to display a message to encourage people to post a comment on your blog if no one has yet posted a comment but remove the message if people have commented you might approach it like this: -
function checkForComments($numberOfComments) {
if ($numberOfComments < 1) {
echo "<p>Be the first to comment on my awesome blog post!";
}
}
The curlybraces {} indicate both the start { and end } of a block of code to be contained within the function and conditional statement respectively. In the example above IF the value of $numberOfComments was 0 (no comments associated with that post) then the condition would be true and the message Be the first to comment on my awesome blog post! would be shown on screen.
IF the value of $numberOfComments is 1 or greater then we already have comments on this post and there is no need to show the message, the condition in our statement is false and the message will not be shown.
I am using a logical operator < which means is less than to determine if the condition is true or false. In plain English you might write: -
if number of comments is less than 1 then show Be the first to comment on my awesome blog post!
Remember in both languages parenthesis are wrapped around arguments and curly braces indicate a body or block of code to be executed within a specific function or condition. There are a few exceptions of course nothing is ever easy but hopefully this explanation has helped rather than hindered!
George Dinmore
518 PointsThat has helped a bit. I am guessing that is PHP?
I think the thing that has thrown me is the fact that Javascript is before PHP on the track, and only touches on the subject briefly. And really, i think it should not be there. However, above you have mentioned the "function" - However, in PHP that has not even been mentioned yet, and yet it has in Javascript.
Richard Duncan
5,568 PointsYes that's PHP but if you replaced echo the syntax would be valid in JavaScript also. The track is probably just illustrating where they are similar JS would also follow the natural flow for an introduction to frontend development after HTML & CSS.
George Dinmore
518 PointsThanks Richard! Appreciate it! Would you advise learning Javascript before entering PHP? Because i noticed you mentioned JQuery, so would i be better off learning off track and learn JQuery then come back to the track?
Richard Duncan
5,568 PointsWhat do you want to do here?
Michael Mangan
9,164 Pointsnode.js is more related to running outside the browser. it does not replace a server-side scripting lanuguage. it is powerful though
George Dinmore
518 PointsGood question! I took this up a hobby at first, and loved html/css. Love it that much, that i want to make a business out of it.
Which direction, not sure.
Richard Duncan
5,568 PointsProbably need to have a think about that before deciding a track then I would guess.
George Dinmore
518 PointsWill do, thanks for everything though.
Richard Duncan
5,568 PointsRichard Duncan
5,568 PointsWordpress is built on PHP so chances are that you will need an understanding of the language to progress down that track too. Both are object orientated and you don't need to understand what this means right now but JavaScript uses prototypal inheritance and PHP uses classical inheritance so depending how far along you are I can see why you might find it confusing learning both at the same time.
Have you tried re-watching the videos? maybe focus on one language first then the other, don't attempt to overload yourself with both at once.