Skip to content
Closed
Show file tree
Hide file tree
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
57 changes: 57 additions & 0 deletions starter-code/basic-algorithms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,64 @@
// Names and Input
var hacker1 = "Andrea";
console.log("The driver's name is " + hacker1);

var hacker2 = window.prompt("Navigator's name?");
console.log("The navigator's name is " + hacker2);

//Conditionals
var hacker1Length = hacker1.length;
var hacker2Length = hacker2.length;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Muy bien, me gusta esta manera de pasar el hacker.length en el condicional 👍 !


if (hacker1Length > hacker2Length) {
console.log("The Driver has the longest name, it has " + hacker1Length + " characters")
} else if (hacker2Length > hacker1Length) {
console.log("Yo, navigator got the longest name, it has " + hacker2Length + " characters")
} else {
console.log("wow, you both got equally long names, " + hacker1Length + " characters!!")
}

// Lorem ipsum generator
var formattedHacker1 = "";

for (var i = 0; i < hacker1Length; i++) {
formattedHacker1 += hacker1.charAt(i).toUpperCase();
if (i < hacker1Length - 1) {
formattedHacker1 += " ";
}
}

console.log(formattedHacker1);

var formattedHacker2 = "";

for (var i = hacker2Length - 1; i >=0; i--) {
formattedHacker2 += hacker2.charAt(i);
}

console.log(formattedHacker2);

var driverNameGoesFirst = false;
var greaterFound = false;
var i = 0;

while (!greaterFound && i < hacker1Length) {
if (hacker1.charAt(i) < hacker2.charAt(i)) {
driverNameGoesFirst = true;
greaterFound = true;
} else if (hacker1.charAt(i) > hacker2.charAt(i)) {
driverNameGoesFirst = false;
greaterFound = true;
}

i++;
}

if (greaterFound) {
if (driverNameGoesFirst) {
console.log("The driver's name goes first");
} else{
console.log("Yo, the navigator goes first definitely");
}
} else {
console.log("What?! You both got the same name?");
}
14 changes: 14 additions & 0 deletions starter-code/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">

<head>
<title>Basic Algorithms</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!--<link rel="stylesheet" href="styles/....">-->
</head>

<body>
<script src="basic-algorithms.js"></script>
</body>
</html>