Skip to content
Open
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
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LAB | JS Basic Algorithms</title>
<script src="index.js"></script>
</head>
<body>
<h1>LAB | JS Basic Algorithms</h1>
<br />
<br />
<p> Open the <a href="https://developer.chrome.com/docs/devtools/open/">Dev Tools console</a> to see the console output.</p>

<script src="index.js"></script>

</body>
</html>
37 changes: 34 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
// Iteration 1: Names and Input

let hacker1 = prompt("Enter your name hacker1"); //The driver's name is XXXX
let space = "";
for(let i = hacker1.length -1; i>=0; i--){//reverse name with spaces
space +=hacker1[i].toUpperCase()+" ";
}
alert(space.trim());

// Iteration 2: Conditionals

let hacker2 = prompt("Enter your name hacker2"); //The navigator's name is YYYY
let space2 = "";
for(let i = hacker2.length -1; i>=0; i--){//reverse name with spaces
space2 +=hacker2[i].toUpperCase()+" ";
}
alert(space2.trim());

// Iteration 3: Loops
//Longest name
if(hacker1.length > hacker2.length){
alert(`Hacker1 has longer name it has ${hacker1.length} characters.`);
}
else if (hacker1.length < hacker2.length){
alert(`Hacker2 has longer name it has ${hacker2.length} characters.`);
}
else{
alert(`Wow, you both have equally long names, ${hacker1.length} characters!`);
}


//Alphabeticaly first
if (hacker1<hacker2){
alert(`The ${hacker1.toUpperCase()} alphabeticaly goes first.`);
}
else if (hacker1>hacker2){
alert(`The ${hacker2.toUpperCase()} is alphabeticaly goes first.`);
}
else{
alert("You have the same name!");
}