Skip to content
Closed
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
var hacker1 = 'Diana'
console.log('The driver\'s name is ' + hacker1)

var hacker2 = result = window.prompt('What\s the 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 + ' character\'s'
)
} else if (hacker1.length == hacker2.length) {
console.log('wow, you both got equally long names, ' + hacker1.length + ' characters!!')
} else {
console.log('Yo, navigator got the longest name, it has ' + hacker2.length + ' characters')
}


// Loops

//6. Print all driver's characters + space in capitals Method 1
var h1UpperCase = hacker1.toUpperCase();
var addSpace = ' ' ;

/* Method 1 try
for (var h1spaces = 0; h1spaces<h1UpperCase.length ; h1spaces = h1spaces + 1) {
var h1spaces = hacker1[0]
console.log(h1spaces)
}*/

//Method 2
console.log(hacker1.split('').join(' ').toUpperCase());


// reverse

var h2Reverse = hacker2.split('').reverse().join('');
console.log(h2Reverse);

//lexicographic order

if (hacker1.toLowerCase()<hacker2.toLowerCase()) {
console.log('The driver\'s name goes first'
)
} else if (hacker1.toLowerCase()>hacker2.toLowerCase()) {
console.log('Yo, the navigator goes first definitely')
} else {
console.log('What?! You both got the same name?')
}

// Palindrome

var newstring = result = window.prompt('Can you tell me a palindrome',"");
if (newstring===result.split('').reverse().join('')) {
console.log('Nice Palindrome')
} else {
console.log('What?!? That\' not a Palindrome')
}


// Lorem ipsum generator
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