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
58 changes: 58 additions & 0 deletions starter-code/basic-algorithms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,65 @@


// Names and Input
// 1)create a variablel hacker1 with the driver's name
let hacker1 = "John"

// 2) print "The driver's name is XXX"
console.log(`The driver's name is ${hacker1}.`);

// 3) create a variable hacker2 and ask the user for the navigator's name
let hacker2 = prompt("What is your name?");

//4) print "The navigator's name is YYY"
console.log(`The navigator's name is ${hacker2}.`);



//Conditionals
// 5) depending on which name is longer, print
if(hacker1.length > hacker2.length) {
console.log(`The driver has the longest name, it has ${hacker1.length} characters`);
}
else if(hacker1.length < hacker2.length) {
console.log(`Yo, navigator got the longest name, it has ${hacker2.length} characters`);
}
else console.log(`wow, you both got equally long names, ${hacker1.length} characters!!`);


// Loops
// 6) Print all the characters of the driver's name, separated by a space and
// in capital letters
console.log(hacker1.split('').join(' ').toUpperCase());

// 7) Print all the characters of the navigator's name in reverse order
console.log(hacker2.split('').reverse().join(''));


// 8) depending on the lexicographic (alphabetic) order of the strings, print

if(hacker1.localeCompare(hacker2) < 0) {
console.log("The driver's name goes first");
}
else if(hacker1.localeCompare(hacker2) > 0) {
console.log("Yo, the navigator goes first definately");
}
else console.log("What?! You both got the same name?");


// 9) ask the user for a new string and check if it is
// a Palindrome (vorwaerts und rueckeaerts gleich)

let hacker3 = prompt("Please enter some text hier: ");

if(hacker3.toLowerCase() === hacker3.toLowerCase().split('').reverse().join('')) {
console.log("This is a Palidrome");
}


// Lorem ipsum generator
// Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.





17 changes: 17 additions & 0 deletions starter-code/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h3>check the console</h3>


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


</body>
</html>
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