Skip to content

lab js basic algorithm #3513

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
20 changes: 10 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" >
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LAB | JS Basic Algorithms</title>
<meta charset="UTF-8">
<title>lab-javascript-basic-algorithms</title>


</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>
<!-- partial:index.partial.html -->

<!-- partial -->
<script src="./script.js"></script>

<script src="index.js"></script>
</body>
</html>
</html>
7 changes: 0 additions & 7 deletions index.js

This file was deleted.

56 changes: 56 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Iteration 1: Names and Input
const hacker1 = "Fee";
let text;
text = `The driver's name is ${hacker1}`;
console.log(text);

let hacker2;
hacker2 = "Harald";
let text2;
text2 = `The navigator's name is ${hacker2}`;
console.log(text2);

// Iteration 2: Conditionals
const lengthDriver = hacker1.length;
const lengthNavigator = hacker2.length;
let text1;
text = `Driver's and navigator's name both have ${lengthDriver} letters.`;

if (lengthDriver > lengthNavigator) {
console.log("Driver's name is longer than navigator's name.");
} else if (lengthDriver === lengthNavigator){console.log(text1);
} else {console.log("Navigator's name is longer than driver's name.");
}

// Iteration 3: Loops
// capital letters and with space
let result1 = "";
for(let i = 0; i < lengthDriver; i ++){
result1 += hacker1[i].toUpperCase() + " ";
}
console.log(result1);

let hacker = "Fee";
let lengthHacker= hacker.length;
let result2 = "";
for (let i = lengthHacker - 1; i >= 0; i--) {
result2 += hacker[i];
}
console.log(result2);


let hacker3 = "Piet";
let hacker4 = "Peter";
let hacker3firstLetter = hacker3[0];
let hacker4firstLetter = hacker4[0];
let textHacker3 = `${hacker3} comes first.`;
let textHacker4 = `${hacker4} comes first.`;
let textBoth = `Both names start with the same letter.`;

if(hacker3firstLetter < hacker4firstLetter){
console.log(textHacker3);
} else if(hacker4firstLetter < hacker3firstLetter){
console.log(textHacker4);
} else{
console.log(textBoth);
}