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
38 changes: 38 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var name = 'Pradeepa';
console.log('Hi ' + name);
//iteration 1

var hacker1 = 'Deepan';
console.log("The driver's name is " + hacker1);
var hacker2 = 'Pradeepa';
console.log("The navigator's name is " + hacker2);
//iteration 2

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('You both got equally long names ' + hacker1.length + ' characters!');
}
//iteration 3

//3.1
const splitDriver = hacker1.toUpperCase();
const arrDriver = [...splitDriver];
console.log(arrDriver.join().replace(/,/g, ' '));
//3.2
const navArr = [...hacker2];
const resArr = [];
for(let i=navArr.length-1;i>-1;i--) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a cool way of solving it! Don't forget about the array.reverse() method as well.

resArr.push(navArr[i]);
}
console.log(resArr.join().replace(/,/g, ''));
//3.3
if(hacker1.localeCompare(hacker2) === 1 ) {
console.log("The driver's name goes first");
} else if(hacker1.localeCompare(hacker2) === -1) {
console.log("Yo, the navigator goes first definitely");
} else {
console.log("What? You both got the same name");
}