Skip to content

Paris - Régis & Laura#225

Closed
laurastromboni wants to merge 3 commits into
ironhack-labs:masterfrom
laurastromboni:master
Closed

Paris - Régis & Laura#225
laurastromboni wants to merge 3 commits into
ironhack-labs:masterfrom
laurastromboni:master

Conversation

@laurastromboni
Copy link
Copy Markdown

console.log("The driver's name is " + hacker1);

var hacker2 = "Régis";
console.log("The navigator's name is " + hacker2);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can interact with the user by asking his name dynamically with the prompt command :

var hacker2 = prompt("What is the navigator's name?");
console.log("The navigator's name is " + hacker2);

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

for (i=0; i < hacker1.length; 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.

remember to always use the "var" keyword when you declare a new variable, otherwise you might envcounter bugs in you code!

for (var i=0; i < hacker1.length; i++){
...
}


for (i=0; i < hacker1.length; i++){
hacker1Array1 += hacker1Up[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.

good logic on this loop and on the one underneath ! You just forgot to do a console.log of hacker1Array1 and hacker1Array2 after each loop to print the result.(Also, these are not technically arrays, they are still strings :) )

}
else {
console.log("What?! You both got the same name?");
}
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 are only comparing the first letter of each name, what if both name start with the same letter but are different names ? (like Niccolò and Nicolas :) )
you can actually compare strings alphabetical order by comparing them directly with the "<" sign :

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

You can check the fist answer here to understand how it works : https://stackoverflow.com/questions/10198257/comparing-2-strings-alphabetically-for-sorting-purposes

}
else {
console.log("It is not a palindrome !");
}
Copy link
Copy Markdown

@ta-web-paris ta-web-paris Oct 16, 2018

Choose a reason for hiding this comment

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

Good, your palindrom code works well !! Try to keep it a bit more organised by putting all of the pieces for this bit of logic together. Also, you dont need to initialize your promptEndroit var with an empty string before asking an input to the user :

var promptEndroit = prompt("Give me a string");
var promptEnvers = "";
for ( var i = promptEndroit.length - 1; i >= 0; i--) {
  promptEnvers += promptEndroit[i];
}

if (promptEndroit === promptEnvers) {
  console.log("It is a palindrome !");
} else {
  console.log("It is not a palindrome !");
}

}
}

console.log("There are " + countEt + " 'et' in this string."); No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again the code works, good job!
You initialised the countEt variable with an empty string up there, but countEt eventually becomes a number. You would be better signaling your intent if you would initialize it with 0 :

var countWords = subSections.split(" ");
var countEt = 0;

console.log("There are " + countWords.length + " words in this string");

for (var i = 0; i < countWords.length; i++) {
  if (countWords[i] === "et") {
    countEt++;
  }
}

console.log(countEt);

@ta-web-paris
Copy link
Copy Markdown

Good job !! Your use of loops is very good and you manage to find solutions to every problems !
Be careful to the readability of your code, this is also a important part of writing good code! It would be easier for your TA's to understand your code if you would divide each exercise is different blocks that you comment instead of declaring all of you variable on the top and performing some logic already there. You can also focus on semantic naming and thinking of variable types :)
Keep up the good work !! 👍 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants