Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
13 changes: 13 additions & 0 deletions 13 index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!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>Palindrome</title>
<script src="palindrome.js"></script>
</head>
<body>

</body>
</html>
90 changes: 90 additions & 0 deletions 90 palindrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
var hacker1 = window.prompt("What is the driver\'s name\?");
console.log("The driver's name is " + hacker1);
var hacker2 = window.prompt("What is the navigator\'s name\?");
console.log("The navigator's name is " + hacker2);

if (hacker1.length > hacker2.length) {
console.log("The Driver has the longest name, it has " + hacker1.length + " characters");
} else if (hacker2.length > hacker1.length) {
console.log("Yo, navigator got the longest name, it has " + hacker2.length + " characters");
} else {
console.log("wow, you both got equally long names, " + hacker2.length + " characters!!");
}

function print (name) {
var printableStr = "";
var letter;
for (var i = 0; i < name.length; i++ ) {
letter = name[i].toUpperCase();
printableStr+=letter;
//if the letter is the last one, no space is needed
if (i!==(name.length-1)) {
printableStr += " ";
}
}
console.log(printableStr);
}

function reversePrint(name) {
var printableStr = "";
var letter;
for (var i = 0; i < name.length; i++ ) {
letter = name[name.length-1-i];
printableStr+=letter;
}
console.log(printableStr);
}

function compare (name1, name2) {
if (name1[0]>name2[0]) {
console.log("Yo, the navigator goes first definitely");
} else if (name1[0]<name2[0]) {
console.log("The driver's name goes first");
} else {
console.log("What?! You both got the same name?");
}
}


function palindrome(stringToCheck) {
var tempStr = stringToCheck.toLowerCase();
var str = "";

//delete whitespace and punctuation
for (var i=0; i<=tempStr.length; i++) {
//add character to the string if the character is a letter
if ((tempStr[i] >= "a") && (tempStr[i] <= "z")) {
str += (tempStr[i]);
}
}

//check if the number of characters is uneven,
//then the middle of the string is a letter
if (str.length%2===1) {
//check if letters to both sides of the middle are same
for (var i=0; i<str.length/2; i++) {
var letterOne = str[str.length/2+1];
var letterTwo = str[str.length/2-1];
if (letterOne !== letterTwo) {
console.log("false");
return false;
}
}
} else {
for (var i=0; i<str.length/2; i++) {
var letter1 = str[i];
var letter2 = str[str.length-1-i];
if (letter1!==letter2) {
console.log("false");
return false;
}
}
}
console.log("true");
return true;
}

print(hacker1);
reversePrint(hacker2);
compare(hacker1, hacker2);
palindrome(window.prompt("Give me a string"));
13 changes: 13 additions & 0 deletions 13 sort.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!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>Sort</title>
<script src="sort.js"></script>
</head>
<body>

</body>
</html>
43 changes: 43 additions & 0 deletions 43 sort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function sort(arrayOfStrings) {

if (!Array.isArray(arrayOfStrings)) {
console.log("wrong input!");
return;
}

for (var i=0; i<arrayOfStrings.length-1; i++) {
for (var j=0; j<arrayOfStrings.length-1-i; j++) {
var string1 = arrayOfStrings[j];
var string1firstLetter = string1[0];
var string2 = arrayOfStrings[j+1];
var string2FirstLetter = string2[0];

if (string1firstLetter>string2FirstLetter) {
arrayOfStrings[j] = string2;
arrayOfStrings[j+1] = string1;
}
}
}

console.log(arrayOfStrings);
}
sort(["qwerty", "asdfg", "zxcvb", "poiuy", "lkjhg", "mnbvc"]);

function findLongest(arrayOfStrings) {
if (!Array.isArray(arrayOfStrings)) {
console.log("wrong input!");
return;
}

var longest = arrayOfStrings[0];

for (var i=1; i < arrayOfStrings.length; i++) {
if (arrayOfStrings[i].length>longest.length) {
longest=arrayOfStrings[i];
}
}
console.log (longest);
return longest;
}

findLongest(["qwerty", "asdfgtt", "zxcvbttt", "poiuytttt", "lkjhgttttt", "mnbvcttt"]);
Morty Proxy This is a proxified and sanitized view of the page, visit original site.