issue66:tutoriel_-_webdev
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue66:tutoriel_-_webdev [2012/10/26 23:14] – créée andre_domenech | issue66:tutoriel_-_webdev [2012/12/17 17:11] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | aLast month we started our CRUD off strong. We didn't go into details by design. I am very fond of teaching by example, and everything in part 1 will start making complete sense now that we are starting to get into JavaScript/ | + | **Last |
I strongly suggest you learn as much as you can about JavaScript. It is a very powerful language, and I guarantee you cannot get away with being a web developer without a strong understanding of it. I am going to give you what I can, but your learning of this language cannot involve just me. | I strongly suggest you learn as much as you can about JavaScript. It is a very powerful language, and I guarantee you cannot get away with being a web developer without a strong understanding of it. I am going to give you what I can, but your learning of this language cannot involve just me. | ||
- | Just about everything we do inside programs involves data. Different types of data have different declarations. For example: 42 is a number, " | + | Just about everything we do inside programs involves data. Different types of data have different declarations. For example: 42 is a number, " |
- | var answer = 42; | + | Le mois dernier, nous avons bien commencé notre application en CRUD. C'est exprès que nous ne sommes pas entrés dans les détails. J'aime vraiment l' |
+ | |||
+ | Je vous suggère fortement d' | ||
+ | |||
+ | Tout ce que nous faisons dans des programmes traite des données. Les différents types de données ont des déclarations différentes. Par exemple : 42 est un nombre, « réponse à la vie » est une chaîne de caractères, | ||
+ | |||
+ | **var answer = 42; | ||
Declaring variables is a pretty simple idea. The above shows an example of the variable " | Declaring variables is a pretty simple idea. The above shows an example of the variable " | ||
Ligne 13: | Ligne 19: | ||
var swVersion = 1.3432 | var swVersion = 1.3432 | ||
yar imageType = " | yar imageType = " | ||
- | var message = "This is a longer string message"; | + | var message = "This is a longer string message"; |
- | Now as you can imagine, this can get really repetitive and somewhat annoying. It also allows for more room for typos. I purposely left two mistakes in the above example and want you to look closely at finding them. Notice that each of these lines ends with a semi-colon. Each line is a statement, and therefore it needs to be ended. JS allows us to clean up our variables by declaring them all at once in one var statement, with one end. Let's clean up this code (shown below) and declare these same variables, then go over what is going on. | + | var reponse = 42; |
+ | |||
+ | La déclaration des variables est une idée assez simple. La ligne précédente montre un exemple de déclaration de la variable « reponse » et une initialisation à la valeur 42. Le mot-clé « var » indique à JavaScript (JS) qu'il s'agit d'une déclaration de variable et que le mot suivant est le nom de la variable que nous déclarons. Le signe d' | ||
+ | |||
+ | var reponse = 42; | ||
+ | var connexion = true; | ||
+ | var swVersion = 1.3432 | ||
+ | yar typeImage = " | ||
+ | var message = "Voici un plus long texte"; | ||
+ | |||
+ | **Now as you can imagine, this can get really repetitive and somewhat annoying. It also allows for more room for typos. I purposely left two mistakes in the above example and want you to look closely at finding them. Notice that each of these lines ends with a semi-colon. Each line is a statement, and therefore it needs to be ended. JS allows us to clean up our variables by declaring them all at once in one var statement, with one end. Let's clean up this code (shown below) and declare these same variables, then go over what is going on. | ||
If you didn't catch the two typos, it was a missing semi-colon on the swVersion declaration and a yar instead of var in the imageType declaration. Debugging your code is very important, and, later on, you’re going to appreciate learning this skill. As for the cleaned up example, we start off the declaration with a var as normal, but instead of ending it on the first line, we have a comma "," | If you didn't catch the two typos, it was a missing semi-colon on the swVersion declaration and a yar instead of var in the imageType declaration. Debugging your code is very important, and, later on, you’re going to appreciate learning this skill. As for the cleaned up example, we start off the declaration with a var as normal, but instead of ending it on the first line, we have a comma "," | ||
var answer = 42, connection | var answer = 42, connection | ||
+ | = true;** | ||
+ | |||
+ | Maintenant, comme vous pouvez l' | ||
+ | |||
+ | Si vous n'avez pas trouvé les deux fautes de frappe, il manquait un point-virgule sur la déclaration swVersion et il y avait un yar au lieu de var dans la déclaration typeImage. Le débogage de votre code est très important et, plus tard, vous allez apprécier l' | ||
+ | |||
+ | var reponse = 42, connexion | ||
= true; | = true; | ||
- | Declaring variables this way makes JS interpret each line as the first example when we only declared one variable. Therefore, it allows us to put the semi colon on a new line as well so we can clean up and see that the declaration of variables has clearly ended. This also allows us to not worry about where the semi-colon is when adding more variables. | + | **Declaring variables this way makes JS interpret each line as the first example when we only declared one variable. Therefore, it allows us to put the semi colon on a new line as well so we can clean up and see that the declaration of variables has clearly ended. This also allows us to not worry about where the semi-colon is when adding more variables. |
The next thing I want to go over is how to make sure your variables are set. This will also help in debugging, and just making sure your code is doing what you expect it does. I am going to show you two ways you can go about this, but the end goal is displaying your information so you can "fact check" as your program moves along. | The next thing I want to go over is how to make sure your variables are set. This will also help in debugging, and just making sure your code is doing what you expect it does. I am going to show you two ways you can go about this, but the end goal is displaying your information so you can "fact check" as your program moves along. | ||
alert(answer); | alert(answer); | ||
- | console.log(answer); | + | console.log(answer); |
+ | |||
+ | Déclarer des variables de cette façon fait que JS interprète chaque ligne comme dans le premier exemple où on n'a déclaré qu'une variable. Par conséquent, | ||
+ | |||
+ | Le sujet suivant que je veux aborder est comment vérifier que vos variables sont initialisées. Cela aidera également dans le débogage et vous permettra de vous assurer que votre code fait ce que vous avez prévu qu'il fasse. Je vais vous montrer deux façons de faire cela, mais l' | ||
+ | |||
+ | alert(reponse); | ||
+ | console.log(reponse); | ||
+ | |||
+ | **Both of the lines above are displaying information to you. Even though they are doing two very different things to give you the information, | ||
+ | |||
+ | The alert function will bring up a dialog box for your attention, requiring you to press " | ||
+ | |||
+ | Les deux lignes ci-dessus vous affichent des informations. Même si elles vous donnent l' | ||
+ | |||
+ | La fonction d' | ||
+ | |||
+ | **The console.log function can take just about anything in its parameter and display all sorts of data in a variety of different ways. I want you to use your main.js script to add variables, and console.log the answers to the JS Console. Play with the alert function as well to give yourself the freedom of choice. So, you will be adding variables to main.js, and opening your HTML file in a browser, while watching what happens in the console. Be sure to do your homework; next month we will be using variables pretty hard core in comparisons, | ||
- | Both of the lines above are displaying information to you. Even though they are doing two very different things to give you the information, they are both giving you that information nonetheless. I know a lot of developers who prefer the alert route. However, I believe it is better practice if you use console.log. Both of these functions are native | + | If you have any questions regarding variables, alert, |
- | The alert function will bring up a dialog box for your attention, requiring you to press " | + | La fonction console.log peut prendre à peu près n' |
- | The console.log function can take just about anything in its parameter and display all sorts of data in a variety of different ways. I want you to use your main.js script to add variables, | + | Si vous avez des questions concernant les variables, |
- | If you have any questions regarding variables, alert, or console.log, |
issue66/tutoriel_-_webdev.1351286093.txt.gz · Dernière modification : 2012/10/26 23:14 de andre_domenech