-
Notifications
You must be signed in to change notification settings - Fork 47
LISFT0123 Pedro Leal - First Lab #13
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: main
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,56 @@ | ||
| // Iteration 1: Names and Input | ||
| console.log("I`m ready"); | ||
|
|
||
| let hacker1 = "The driver's name is Leal"; | ||
| let hacker2 = "The navigator's name is Duarte"; | ||
|
|
||
| // Iteration 2: Conditionals | ||
|
|
||
| let driverName = hacker1.slice(21); | ||
|
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. So here you wouldn't need to use |
||
| let navigatorName = hacker2.slice(24); | ||
|
|
||
|
|
||
|
|
||
| let numOfCharDriver = driverName.length; | ||
| let numOfCharNavigator = navigatorName.length; | ||
|
|
||
|
|
||
| if( driverName.length > navigatorName.length){ | ||
|
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. Great job on creating the variables
|
||
| console.log("The driver has the longest name, it has " + numOfCharDriver + " characters"); | ||
| } | ||
| if(driverName.length < navigatorName.length){ | ||
| console.log("It seems that the navigator has the longest name, it has "+ numOfCharNavigator + " characters."); | ||
| } | ||
| else { | ||
| console.log("Wow, you both have equally long names, " + numOfCharDriver + " characters!"); | ||
| } | ||
|
|
||
|
|
||
| // Iteration 3: Loops | ||
|
|
||
| //3.1 | ||
| for (let i = 0; i < driverName.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. Here, the idea was to print all the characters of the driver's name, separated by a space and in capitals i.e. "L E A L". A good solution would be: |
||
| console.log(driverName.toUpperCase()[i]); | ||
| console.log(driverName.toUpperCase()[0]+ " " + driverName.toUpperCase()[1] + " " + driverName.toUpperCase()[2] + " " + driverName.toUpperCase()[3]); | ||
| } | ||
|
|
||
| //3.2 | ||
|
|
||
| for(let i = navigatorName.length -1 ; i >= 0; 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. Here, the idea was to print all the characters of the navigator's name in reverse order. i.e. "etrauD" One way of doing that: |
||
| console.log(navigatorName[i]); | ||
| } | ||
|
|
||
| //3.3 | ||
|
|
||
| if (hacker1 > hacker2) { | ||
|
|
||
| console.log (`The driver's name goes first.`) | ||
|
|
||
| } else if (hacker1 < hacker2) { | ||
|
|
||
| console.log (`Yo, the navigator goes first definitely.`) | ||
|
|
||
| } else { | ||
|
|
||
| console.log (`What?! You both have the same name?`) | ||
| } | ||
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.
Here, instead of passing the variable as the whole string, you could've given just your name and console.log the string after, like: