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
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!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>
<script type='text/javascript' src='./starter-code/basic-algorithms.js'></script>
</body>
</html>
79 changes: 77 additions & 2 deletions starter-code/basic-algorithms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,82 @@
// Names and Input

// 1
let hacker1 = 'Dave';
// 2
console.log(`The driver's name is ${hacker1}`);
// 3
let hacker2 = prompt(`What's the navigators name?`);
// 4
console.log(`The navigator's name is ${hacker2}`);

//Conditionals
// 5
hacker1Len = hacker1.length;
hacker2Len = hacker2.length;

if(hacker1Len > hacker2Len) {
console.log(`The Driver has the longest name, it has ${hacker1Len} characters`);
} else if(hacker1Len < hacker2Len) {
console.log(`Yo, navigator got the longest name, it has ${hacker2Len} characters`);
} else {
console.log(`wow, you both got equally long names, ${hacker1Len} characters!!`);
}

// Loops
// 6: Driver's name separated by a space and in capitals
var capital = ''
for (let i = 0; i < hacker1.length; i++) {
if(i == (hacker1.length - 1)){
capital += hacker1[i];
}else{
capital += hacker1[i] + ' ' ;
}
}
console.log(capital.toUpperCase());

// 7: Navigator's name in reverse order
var reverse = '';
for (let i = hacker1.length - 1; i >= 0; i--) {
reverse += hacker1[i];
}
console.log(reverse);

// 7: Navigator's name in reverse order (Built-In functions)
console.log(hacker1.split("").reverse().join(""));

// 8: lexicographic order
var sortNames = [hacker1, hacker2];
console.log(sortNames.sort());
if(sortNames[0] == sortNames[1]){
console.log('What?! You both got the same name?');
} else if(sortNames[0] == hacker1) {
console.log('The driver\'s name goes first');
} else {
console.log('Yo, the navigator goes first definitely');
}

// Bonus Time!
// 9: Palindrome
var palindrome = prompt("Insert a palindrome: ");
console.log(palindrome);
palindrome = palindrome.toLowerCase().replace(/[^A-Za-z0-9]/g, '');
var len = palindrome.length;
var isPalindrome = true;
for (var i = 0; i < len / 2; i++) {
if (palindrome[i] !== palindrome[len - 1 - i]) {
isPalindrome = false;
}
isPalindrome
}

console.log((!isPalindrome) ? 'It\'s not a palindrome' : 'It\'s a palindrome');

// Lorem ipsum generator
// 10: Lorem Ipsum
var lorem = `Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.`;
var totalWords = 1;
var countEt = 0;
for (var i = 0; i < lorem.length; i++) {
if (lorem[i] === " ") totalWords+=1;
}
var countEt = (lorem.match(/ et/g)).length;
console.log(lorem);
console.log(`Total words: ${totalWords}. 'ET' words: ${countEt}`);
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