Part28. What is the problem with my code?


#1

Hello,

So I'm on part 28 of the javascript program and it doesn't work. I may have made a syntax error but I can't find it.
Can someone help me?
Here is the code:

var confirm = confirm.("Have you finished the first JS coding part?");
confirm.("Have you finished the first JS coding part?");
if (confirm === true){
console.log(I finished my first course!);}
else {
console.log(Then finish it, it is worth the work);}


#2

This should work now, at least syntactically it's correct.

var message = confirm("Have you finished the first JS coding part?");
if (message === true){
console.log('I finished my first course!');}
else {
console.log('Then finish it, it is worth the work');
}

You made a few minor mistakes. You're trying to change "confirm" function value. Don't use reversed keywords, variables, objects or you will get errors. And I'm not sure why you put the same message twice.
You also don't need . after confirm.


#3

Thanks !
I thought that after declaring the variable 'message', i should use the confirm() to make the pop-up appear. Guess not.

Also, because I advanced a bit in the course, how can you use console.log() to print a string + myName variable?


#4

If that's what you're asking:

var myName = 'Name';

console.log('Your name is: ' + myName);

If you want to display string and variable value you have to join/concatenate string and variable. Strings must be always wrapped between single or double quotes and + sign will concatenate your variable value with that string.


#5

Thanks again, I appreciate your help.

I can understand that single and double quotes have the same behavior then?


#6

You'll want to use single quotes where you want double quotes to appear inside the string without having to escape them, or vice versa. Other than that, there is no difference.

Examples:

console.log('I'm learning'); - JavaScript will have a problems interpreting this string. If you want to use single quotes inside your string when you have to wrap your string with double quotes like this:
console.log("I'm learning");

The same thing here, when you want to use double quotes inside string, you have to wrap your string with single quotes:
console.log('I"m learning');

Or alternatively, you can even wrap and use the same quotes if you escape it (just put \ after every quote):

console.log('\I\'m learning'); - it will log to the console - I'm learning


#7

That will be helpful to continue.

Just to know, when did you learn JS? And what do you develop with it?


#8

I don't even remember when I learned it, but that was very long time ago. To be honest, I'm still learning it, I mean to get better in more advanced stuff. Learning is sometimes never ending story. There will be new JavaScript versions released and I'm trying to keep up with it, to feel confident when programming and stay up to date. My experience in JavaScript is probably 8+ years.

I did a lot of stuff with JavaScript and still going forward, I mean I'm able to create more complex things than I used to, only practice and frequent reading about it will get you better at it and no other shortcuts. Currently I'm developing JavaScript framework but it's just a contribution to some projects. You can develop with JS probably anything you can imagine on the web, it helps to add interactivity to websites easily. If you're not sure of what you can do with JavaScript then try to find JavaScript cool examples or projects.


#9

I'm interested in starting developing some chrome extensions. And I want to familiarize with other languages, although I'll take a step at a time.

Do you have any good IDE to recommend? Some JS ones for example?


#10

Many JavaScript programmers would consider JetBrains WebStorm IDE as the best JavaScript IDE but this is something that you have to find out for yourself. There are many JavaScript IDEs and code editors and for many people it's just a preference. I've also tried Aptana Studio, Eclipse IDE for JavaScript Web Developers, NetBeans IDE.

I like Sublime Text Editor (this is what I'm currently using now for web development, it's quite fast and convenient editor without too much functionality, you can download a lot of free extensions to extend functionality so it's even more powerful), Adobe Brackets, Atom.io these are also quite new and quite lightweight in size. And of course you can find even more using any search engine like Google, Yahoo or Bing.

It takes time to get really comfortable with IDEs but it's worth it. Although many people will recommend you IDEs, but for me I find that it's faster and easier to use just lightweight code editors especially when I'm learning something new or when building small to medium projects. Just try a few code editors and IDEs of course you will lose your precious time but in the future it pays off and you will definitely end up more productive.