-
Notifications
You must be signed in to change notification settings - Fork 58
Samuel Ledeboer BCN FT #66
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
base: master
Are you sure you want to change the base?
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,41 @@ | ||
| // Names and Input | ||
| //variables | ||
| var hacker1 = "Samuel" | ||
| var hacker2 = window.prompt("what is the navigators name?") | ||
|
|
||
|
|
||
| //Conditionals | ||
| //console logs | ||
| console.log(`The drivers name is ${hacker1}`); | ||
| console.log(`The navigators name is ${hacker2)}`) | ||
|
|
||
|
|
||
| // Lorem ipsum generator | ||
| //Let's get looping | ||
| for (var i = 0; i < hacker1.length || hacker2.length; i++){ | ||
| 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(`wow, you both got equally long names, ${hacker2.length} characters!!`) | ||
| } | ||
|
|
||
| //loop drivers name | ||
| for(let i = 0; i < hacker1.length; i++){ | ||
| console.log(`${hacker1[i]}`) | ||
| } | ||
|
|
||
| //loops driver name backwards | ||
| for(let i = hacker.length; i > 0; i--){ | ||
|
Collaborator
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 for 'samuel' backwards you'd get 'amuel', missing the first letter. To reach the first letter you need to iterate backwards and set the condition of the for loop (the middle statement) to also equal 0, just like this: for(let i = hacker.length; i >= 0; i--) You only forgot to add the equal symbol |
||
| console.log(`${hacker1[i]}`) | ||
| } | ||
|
|
||
|
|
||
|
|
||
| //loop on first letter.. | ||
| for(let i = 0; i < 1; i++){ | ||
| if (hacker1[0] === "a"){ | ||
| console.log(`The driver's name goes first`) | ||
| } else if (hacker2[0] === "a"){ | ||
| console.log(`Yo, the navigator goes first definitely`) | ||
| } else {} | ||
| console.log(`What?! You both got the same name?`) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
The challenge here was to compare the length of two element. It would have been easier to just compare element1.length and element2.length with no need to use a for loop since you can get the length of a string directly with the ".length()" property. Then you only return the one that is longer (if element1.length < element2.length return element2)