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
42 changes: 42 additions & 0 deletions starter-code/basic-algorithms.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
var hacker1 = prompt("Enter the driver's name"); console.log("The driver's name is " + hacker1);


var hacker2 = prompt("Enter the navigator's name"); console.log("The navigator's name is " + hacker2);
if (hacker1.length === hacker2.length) {
console.log("wow, you both got equally long names, " + hacker1.length + " characters!!") }
else if (hacker1.length <= hacker2.length) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you don't want to be checking if it's greater than or equal to- you only want to check to see if it is greater than since you're checking for the longest name

console.log("Yo, navigator got the longest name, it has " + hacker2.length + " characters"); }
else {
console.log("The Driver has the longest name, it has " + hacker1.length + " characters"); }


var spaceDriver = "";
for (i = 0; i <= hacker1.length -1; i++) {
spaceDriver+=(hacker1[i])+" ";
}
console.log(spaceDriver.toUpperCase());


var reverseNavigator = "";
for (i = hacker2.length -1; i >=0; i--) {
reverseNavigator+=(hacker2[i]);
}
console.log(reverseNavigator);


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

var alphabet = "abcdefghijklmnopqrstuvwxyz";
var candidate = prompt("Testez la palindromie du mot");
for (i=0 ; i <= candidate.length-1; i++) {
if (!alphabet.includes(candidate[i])) {candidate=candidate.substr(0,i-1)+candidate.substr(i+1,candidate.length-1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure what you are trying to do here. There is an easier way to check to see if it's a palindrome


if (nameNormal.replace(" " ,"") === nameReversed.replace(" ", "")) {
  console.log("It's a palindrome !!");
} else {
  console.log("It's not a palindrome...");
};

i--;}
}
console.log(candidate);

// Names and Input


Expand Down