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

JavaScript

Srdjan Cestic
Srdjan Cestic
6,855 Points

JavaScript and logic in programming

Hi everyone, I start learning JavaScript, and I'm start with Basic course.

I have idea how to solve challenge's, but I have problem with logic part of programming and I have some obscurity in understanding different parts of code.

In fact, I don't solve any challenge without asking on forum other members.

In fact I think I have problem with logic in programming, because I so far learn HTML and CSS in front end and web design track, and JavaScript is a lot different type of language.

My question is, can you provide me some tips or maybe tricks to learn more efficient (Any type of language, not just JS) ?

And is there any language that you can reccomend to learn programming? I mean, some language that will give me strong foundation/base, and after that switch to other languages easily?

Regards, Srdjan

Jeremy Canela
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jeremy Canela
Full Stack JavaScript Techdegree Graduate 30,766 Points

I think since HTML and CSS are not programming languages, you're having troubles starting out learning your first (I assume) programming language. I'm not sure of what parts of JavaScript you're not understanding. If you can describe a little more about what you don't understand, I'll try to clarify.

9 Answers

Nicholas Olsen
seal-mask
.a{fill-rule:evenodd;}techdegree
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 Points

There is really no easy way around this. Your first programming language is going to be hard to learn. The best approach I think is to understand the fundamental parts of any language. Every language has:

  • Some way to assign values to a symbol (variables, constants)
  • Branching (switch statements, if-else statements)
  • Iteration (while loops, for loops)
  • Composite Data Types (arrays, lists, tuples, hashes, objects, etc)
  • More stuff I'm probably not qualified to outline like scoping

That being said, Javascript is an unusual and quirky language which might add to the difficulty. If you'd like to start with another language, I'd recommend Python.

Nicholas Olsen
seal-mask
.a{fill-rule:evenodd;}techdegree
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 Points

Jeremy Canela I was commenting mainly on his issues with the logic of programming, which is fairly similar regarding all languages (all languages have mechanisms for branching, iterations, etc). Javascript is hard to grasp if you have earlier programming experience and are used to classical inheritance or haven't messed around much with functional languages like Scheme. But it doesn't sound like he has any previous programming experience. Otherwise, the difficulty tends to be with the bad design details like how == does type coercion or the frontend environment overall. (In other words, not really logic stuff)

jason chan
jason chan
31,009 Points

javascript takes a long while to understand. It's based on functional programming and it's quirky language that keeps on changing. es2015 just came out.

I also recommend python or php.

Srdjan Cestic
Srdjan Cestic
6,855 Points

I will certainly learn it, thanks again! :)

Srdjan Cestic
Srdjan Cestic
6,855 Points

Hi everyone, I will first start with answering on Jeremy question. Operators and combination of different parts of code in entirety, that's my main problem so far, for example numbers guessing game (bottom number and top number).

Nicholas and Jason, I need to know JavaScript to become Front End developer, so when would I know am I ready to call myself as junior in that field? When I know how to build interactive webpage, or maybe some quiz or some simillar, or when I know fundamentals of every concept in JavaScript (Nicholas mentoin that in his comment)?

So Python will be good language to learn along JavaScript, right?

Thanks for help

Jeremy Canela
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jeremy Canela
Full Stack JavaScript Techdegree Graduate 30,766 Points

JavaScript operators can be assigning variable names to values. It can be adding 2 numbers in a variable or concatenating strings. Also don't be afraid to look up other things on google if you absolutely don't understand something. Here is a link to learn more about JavaScript Operators. If you can give an example of code you don't understand on the guessing game, please comment the code below :)!

Srdjan Cestic
Srdjan Cestic
6,855 Points

I understand. When would I know am I really learn, and when I can be sure that I know JavaScript enough to call myself Front End developer? When I know how to build interactive webpage, or maybe some quiz or some simillar, or when I know fundamentals of every concept in JavaScript (Nicholas mentoin that in his comment)?

This is example of guessing game : // QUIZ var number1 = prompt("Please type some number here"); var firstNumber = parseInt(number1); var number2 = prompt("Please type second number here"); var secondNumber = parseInt(number2); var randomNumber = Math.round(Math.random() * (firstNumber + 1)) + firstNumber; var sentence = " Hi, is your number " + randomNumber + "?"; document.write(sentence);

Srdjan Cestic
Srdjan Cestic
6,855 Points

var = randomNumber, that's the part of code I can understand clear.

Jeremy Canela
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jeremy Canela
Full Stack JavaScript Techdegree Graduate 30,766 Points
// QUIZ
// The Prompt function opens up a prompt box with an input field. Once the user clicks "Ok", the value from the input field in the prompt will be stored in the variable number1.
var number1 = prompt("Please type some number here");

// The parseInt function converts a string that contains a number and turns it into a number value.
var firstNumber = parseInt(number1);

// This is the same as above for the number1 variable.
var number2 = prompt("Please type second number here");

// Same as firstNumber
var secondNumber = parseInt(number2);

/*
I won't try to explain much of what each function here does, but check the links below. The Math.round() just rounds a number up or down depending on its decimal. Examples:

Math.round(99.21) = 99
Math.round(90.5) = 91

The Math.random() just returns a number between 0 and 1 by default.
*/
var randomNumber = Math.round(Math.random() * (firstNumber + 1)) + firstNumber;

// This is just a string concatenated with the variable randomNumber.
var sentence = " Hi, is your number " + randomNumber + "?";

// This just outputs the value of sentence on the page.
document.write(sentence);

Links

I know this might be a little hard to understand, but if you are not clear on what some functions do, just google them. I recommend W3Schools because they give many examples.

Srdjan Cestic
Srdjan Cestic
6,855 Points

Thanks for great help Jeremy!

Can you just answer me on this question : When would I know am I really learn, and when I can be sure that I know JavaScript enough to call myself Front End developer and add that language to my CV? When I know how to build interactive webpage, or maybe some quiz or some simillar thing, or when I know fundamentals of every concept in JavaScript (Nicholas mentoin that in his comment)?

Jeremy Canela
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jeremy Canela
Full Stack JavaScript Techdegree Graduate 30,766 Points

That's a really good question. That's something you have to decide. When you think you have a good amount of knowledge of JavaScript, if someone asks you to create something, you'll be able to create it. A quiz is something simple, although it can become a little more complex than just questions and an input field. Having good knowledge of JavaScript is being able to create and customize for example online graphs, geolocation which is getting a user's location and doing something with that data, creating games with javascript, etc. Most companies require you to use javascript frameworks such as jQuery, AngularJS, BackboneJS, NodeJS, and many, MANY more. JavaScript is a big language, and you can build infinite things with the language. So the answer to your question: When you feel like you're ready :)

Srdjan Cestic
Srdjan Cestic
6,855 Points

Thanks Jeremy on great explain answer.

I really do a lot research for Front End developer position, what languages is must etc. and there is next : HTML, CSS, JavaScript and jQuery is must, but Front End track teach also SaSS, Ajax, Responsive design. So I think that will be enough to start looking and finally working as Front End developer, I really ask many peoples about that, so when I considered all answers/opinions, that's some real rating or opinion. http://learntocodewith.me/wp-content/uploads/2014/11/front-end-mind-map.png http://learntocodewith.me/wp-content/uploads/2014/12/frontend-skills.jpg

Srdjan Cestic
Srdjan Cestic
6,855 Points

In my opinion, JavaScript is harder than other languages I know. jQuery makes it extremely easy to use JavaScript.

Jeremy when you said this, did you mean that when I learn jQuery, I will get more clearer and better understanding of JavaScript, and I will can actually put it in my projects in future?

Jeremy Canela
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jeremy Canela
Full Stack JavaScript Techdegree Graduate 30,766 Points

When I said that, I meant that jQuery will make it easy to work with JavaScript. jQuery will make it extremely easy to work with AJAX, JSON files, making your site interactive, etc. I highly recommend you learn how to use it if you haven't :)!

Joseph Torres
Joseph Torres
6,282 Points

Hello Srdjan Cestic, I know you posted this almost 3 years ago but I was curious to know how are you coming along in your JS?