-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[wedptmad0418] Edna Domingos #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,118 @@ | ||
| // Names and Input | ||
| var hacker1=prompt("What is the name of your driver?") | ||
|
|
||
| console.log( "The driver's name is "+ hacker1); | ||
|
|
||
| var hacker2 = prompt("What is the name of your navigator?"); | ||
|
|
||
| console.log( "The navigator's name is "+ hacker2); | ||
|
|
||
| //for (hacker1 = 0;hacker1<hacker2.lenght;hacker1++) | ||
|
|
||
| if (hacker1.length > hacker2.length) { | ||
|
|
||
| console.log ("The Driver has the longest name, it has " + hacker1.length + " character"); | ||
|
|
||
| } else if (hacker1.length<hacker2.length) { | ||
|
|
||
| console.log ("uy navigator got the longest name,it has " + hacker2.length+ " characters"); | ||
|
|
||
| } else { | ||
|
|
||
| console.log ("wow, you both got equally long names, " + hacker1.length + " characters!!"); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| hacker1=hacker1.toUpperCase() + ""; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| space = "", | ||
| navegator = hacker1.split(space); | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Está bien igualar variables para acortar lo que tienes que escribir, pero en el caso de tu variable 'space', que además has olvidado declarar el tipo de variable (var), escribes más poniendo 'space' que las comillas. |
||
| console.log(navegator); | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Te falta pasarlo a cadena y separar cada letra por espacios. La función split( ) convierte la cadena sobre la que estás trabajando en un array separando cada elemento en función del argumento que le des a split( ) |
||
|
|
||
|
|
||
| function reverse(s) { | ||
| var o = ''; | ||
| for (var i = s.length - 1; i >= 0; i--) | ||
| o += s[i]; | ||
| return o; | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bien hecho, pero intenta usar nombres de variables que definan bien el sentido que tienen, s podría ser mejor string y la o podría ser mejor newString. Una vez que sabes cómo invertir la cadena manualmente, échale un ojo a las funciones split( ), reverse( ) y join( ) |
||
| console.log(reverse(hacker2)); | ||
|
|
||
|
|
||
| if (hacker1.toLowerCase() < hacker2.toLowerCase()){ | ||
|
|
||
| console.log("The driver's name goes first"); | ||
|
|
||
| }else if (hacker1.toLowerCase() > hacker2.toLowerCase()) { | ||
|
|
||
| console.log("Yo, the navigator goes first definitely"); | ||
|
|
||
| } else{ | ||
|
|
||
| console.log("What?! You both got the same name?"); | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| function palindromo(cadena) { | ||
|
|
||
| var resultado = "La cadena \""+cadena+"\" \n"; | ||
|
|
||
| // minusculas la cadena | ||
| var cadenaOriginal = cadena.toLowerCase(); | ||
|
|
||
| // Convertir la cadena en un array | ||
| var letrasEspacios = cadenaOriginal.split(""); | ||
|
|
||
| // Eliminar los espacios en blanco | ||
| var cadenaSinEspacios = ""; | ||
| for(i in letrasEspacios) { | ||
| if(letrasEspacios[i] != " ") { | ||
| cadenaSinEspacios += letrasEspacios[i]; | ||
| } | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Por qué has usado for...in y no el otro bucle for? |
||
| var letras = cadenaSinEspacios.split(""); | ||
| var letrasReves = cadenaSinEspacios.split("").reverse(); | ||
|
|
||
| //Comprobar si es palindromo o no | ||
| var iguales = true; | ||
| for(i in letras) { | ||
| if(letras[i] == letrasReves[i]) { | ||
| // Todo bien | ||
| } | ||
| else { | ||
| // Alguna letra es distinta, por lo que ya no es un palindromo | ||
| iguales = false; | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Para ahorrar líneas si niegas la primera condición te ahorras el else: |
||
|
|
||
| if(iguales) { | ||
| resultado += " es un palíndromo"; | ||
| } | ||
| else { | ||
| resultado += " no es un palíndromo"; | ||
| } | ||
|
|
||
| return resultado; | ||
| } | ||
|
|
||
| console.log(palindromo("Amor, Roma")); | ||
| console.log(palindromo("Esta frase no se parece a ningun palindromo")); | ||
|
|
||
| //Conditionals | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Por qué concatenas comillas al final?, las comillas sin espacio es igual a nada. No son necesarias