Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion starter-code/basic-algorithms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,57 @@
// Names and Input
let hacker1 = "Cristopher"
console.log("The Driver's name is " + hacker1)
let hacker2 = prompt ("Enter your name")
console.log("The Navigator's name is " + hacker2)
let palindromo = prompt ("Escribe un palindromo")
Copy link

@ta-web-mex ta-web-mex Aug 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tratemos de tener un código ordenado, conforme a las iteraciones que nos va pidiendo el ejercicio, el palíndromo es el penúltimo bonus, mas adelante veremos que javascript es un leguaje asincrono, y podemos declarar nuestras variables en la parte donde las vamos a necesitar.



//Conditionals

//Conditionals
if (hacker1.length > hacker2.length){
console.log("The Driver has the longest name, it has "+ hacker1.length +" characteres")
}else if (hacker1.length < hacker2.length){
console.log("The Navigator has the longest name, it has "+ hacker2.length +" characteres")
}else {
console.log("wow, you both got equally long names " + hacker1.length +", characteres!!")
}
let hacker3 =hacker1.toUpperCase()
hacker3= hacker3.split('')

let espacios = ''
for(let i= 0; i<hacker3.length; i++){
espacios += hacker3[i]+ ' '
}
console.log(espacios)

let espacios2 = ''
for(let i= hacker2.length-1; i>=0; i--){
espacios2 += hacker2[i]+ ' '
}
console.log(espacios2)

let ordenalfa= hacker1.localeCompare(hacker2)
if(ordenalfa===-1){
console.log("The driver's name goes first ")
}else if (ordenalfa===1){
console.log("yo, the navigator goes first definitely")
} else{
console.log("what!? you both got the same name?")
}



function palindrome (palindromo){
let remove = palindromo.replace(/[^A-Z0-9]/ig,'').toLowerCase();

let check = remove.split('').reverse().join('');

if (remove === check){
console.log(palindromo + " it's a palindrome")
} else {
console.log(palindromo + " isn't a palindrome")
}
}
palindrome (palindromo)

// Lorem ipsum generator
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy