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
31 changes: 31 additions & 0 deletions starter-code/basic-algorithms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
// Names and Input
var hacker1 = "Montse";
console.log("The driver's name is " + hacker1);

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

//Conditionals
if (hacker1.length > hacker2.length) {
console.log("The driver has the longest name, it has " + hacker1.length + "characters.")
} else if (hacker2.length > hacker1.length) {
console.log("The navigator has the longest name, it has " + hacker2.length + "characters.")
} else {
console.log("Wow, you both got equally long names, " + hacker1.length + "characters!!!!!!!")
};

var name = "";
var uppercase = hacker1.toUpperCase();
var name2 = "";
for (var i=0; i<hacker1.length; i++) {
name += uppercase[i]+ " ";

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.

cool!

}
console.log(name);
var value = hacker1.length -1;

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.

it's ok, but you don't need to create a variable for that. It will not modify its value if you modify the hacker1 variable later in your program.

for (var i=value; i>=0; --i) {

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.

you can do then:

for (var i=hacker1.length -1; i>=0; --i) {

name2 += hacker1[i];
}
console.log(name2);


// Lorem ipsum generator
if (hacker1 > hacker2) {
console.log("The driver's name goes first.")
} else if (hacker2 > hacker1) {
console.log("The navigator's name goes first.")
} else {
console.log("You both have the same name.")
};

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.

👍

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>Hello, world!</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>

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