-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Paris - Régis & Laura #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,82 @@ | ||
| // Names and Input | ||
|
|
||
| var hacker1 = "Laura"; | ||
| console.log("The driver's name is " + hacker1); | ||
|
|
||
| var hacker2 = "Régis"; | ||
| console.log("The navigator's name is " + hacker2); | ||
|
|
||
| hacker1Up = hacker1.toUpperCase(); | ||
|
|
||
| var hacker1Array1 = ""; | ||
|
|
||
| console.log(hacker1Array1); | ||
|
|
||
| var hacker1Array2 = ""; | ||
|
|
||
| console.log(hacker1Array2); | ||
|
|
||
| var promptEndroit = ""; | ||
| var promptEnvers = ""; | ||
|
|
||
| promptEndroit = prompt("Give me a string"); | ||
|
|
||
| var subSections = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." ; | ||
|
|
||
| var countWords = subSections.split(" "); | ||
|
|
||
| var countEt = "" ; | ||
|
|
||
|
|
||
| //Conditionals | ||
|
|
||
| if (hacker1.length === hacker2.length){ | ||
| console.log("wow, you both got equally long names, " + hacker1.length + " characters!!"); | ||
| } | ||
| else if (hacker1.length > hacker2.length){ | ||
| console.log("The Driver has the longest name, it has " + hacker1.length + " characters"); | ||
| } | ||
| else { | ||
| console.log("Yo, navigator got the longest name, it has " + hacker2.length + " characters"); | ||
| } | ||
|
|
||
| for (i=0; i < hacker1.length; i++){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! |
||
| hacker1Array1 += hacker1Up[i] + " " ; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :) ) |
||
|
|
||
| for (i=hacker1.length-1;i >= 0; i--){ | ||
| hacker1Array2 += hacker1[i]; | ||
| } | ||
|
|
||
| if (hacker1[0] > hacker2[0]){ | ||
| console.log("Yo, the navigator goes first definitely"); | ||
| } | ||
| else if (hacker1[0] < hacker2[0]){ | ||
| console.log("The driver's name goes first"); | ||
| } | ||
| else { | ||
| console.log("What?! You both got the same name?"); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 check the fist answer here to understand how it works : https://stackoverflow.com/questions/10198257/comparing-2-strings-alphabetically-for-sorting-purposes |
||
|
|
||
| for (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 !"); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 : |
||
|
|
||
| // Lorem ipsum generator | ||
|
|
||
| console.log("There are " + countWords.length + " words in this string"); | ||
|
|
||
| for (i=0;i<countWords.length;i++){ | ||
| if (countWords[i] === "et"){ | ||
| countEt ++; | ||
| } | ||
| } | ||
|
|
||
| console.log("There are " + countEt + " 'et' in this string."); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again the code works, good job! |
||
There was a problem hiding this comment.
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 :