Variables: guardar información
Un programa que no recuerda nada no sirve para nada. Acá aprendes a guardar cosas.
Variables: storing information
A program that remembers nothing is useless. Here you learn to store things.
Una variable es una caja donde guardas algo y le pones un nombre, para poder pedirlo después.
Se crea con la palabra let, seguida del nombre que tú elijas, un signo
= y lo que quieras guardar.
A variable is a box where you store something and give it a name, so you can ask for it later.
You create it with the word let, then a name you choose, an =
sign, and whatever you want to store.
El signo = no significa "es igual a"
como en matemáticas. Significa "guarda esto acá". Se lee de derecha a izquierda:
toma "Joaco" y métele eso a la caja llamada nombre.
The = sign does not mean "equals"
like in maths. It means "store this here". Read it right to left: take "Joaco" and
put it into the box called nombre.
Se llaman variables porque su contenido puede variar. Para
cambiarlo no repites el let: solo el nombre y el nuevo valor.
Acá está el corazón de cualquier marcador de puntos:
They are called variables because their contents can vary. To
change one you do not repeat let: just the name and the new value.
Here is the heart of any scoreboard:
Hay dos formas de crear una variable, y la diferencia es simple:
let— para cosas que van a cambiar: puntos, vidas, posición.const— para cosas que no cambian nunca: la gravedad, el color de la marca, la cantidad máxima de vidas.
¿Y para qué sirve limitarse a propósito? Para que el computador te avise si intentas cambiar algo que no debías. Es una red de seguridad contra tus propios descuidos.
There are two ways to create a variable, and the difference is simple:
let— for things that will change: score, lives, position.const— for things that never change: gravity, the brand colour, the maximum number of lives.
Why limit yourself on purpose? So the computer warns you if you try to change something you should not. It is a safety net against your own slips.
Ya lo viste con las comillas, pero acá es donde muerde de verdad. Al + le
pasa algo curioso: con números suma, con textos pega uno detrás del
otro.
You saw this with the quotes, but this is where it really bites. The + does
something curious: with numbers it adds, with text it sticks one
after the other.
Ese "53" es uno de los errores más comunes al
empezar, y aparece siempre que tomas un dato escrito por el usuario: lo que se
escribe en un formulario siempre llega como texto, aunque parezca un número.
Para convertirlo se usa Number().
That "53" is one of the most common beginner bugs,
and it shows up whenever you take input from a user: whatever someone types into a
form always arrives as text, even if it looks like a number.
To convert it you use Number().
Un consejo que vale más de lo que parece: el nombre de la variable debe decir qué guarda. Tu yo de la próxima semana te lo va a agradecer.
let v = 3;— ¿tres qué? Vidas, velocidad, veces…let vidasRestantes = 3;— se entiende solo.
Reglas: no pueden llevar espacios ni empezar con número, y en JavaScript se acostumbra a
unir las palabras con mayúscula en medio, así: vidasRestantes,
puntajeMaximo.
Ojo, las mayúsculas importan: edad y Edad son
dos variables distintas.
Advice worth more than it sounds: the variable name should say what it holds. Next week's you will thank you.
let v = 3;— three what? Lives, speed, times…let livesLeft = 3;— self-explanatory.
Rules: no spaces, cannot start with a number, and in JavaScript the convention is to join
words with a capital in the middle: livesLeft, maxScore.
Careful, capitals matter: age and Age are two
different variables.
Crear variables con let y const. Cambiar su valor. La diferencia
entre texto y número, y por qué "5" + "3" da "53". Y ponerles
nombres que se entiendan.
Ahora que el programa puede recordar, viene lo bueno: que decida.
Creating variables with let and const. Changing their value. The
difference between text and numbers, and why "5" + "3" gives "53".
And naming them so they make sense.
Now that your program can remember, here comes the good part: making it decide.