Skip to content

Instantly share code, notes, and snippets.

@horsfallnathan
Last active May 1, 2019 07:12
Show Gist options
  • Save horsfallnathan/c9d58e22f504b5796d0ca1f11c7d6574 to your computer and use it in GitHub Desktop.
Save horsfallnathan/c9d58e22f504b5796d0ca1f11c7d6574 to your computer and use it in GitHub Desktop.
Test2

Corrections

  • You dont need {} everytime for an expression, you only use it to segment blocks of code you want separate from other processes.
  • You didn't need this line: let letterCount = StringB.replace(/\s+/g, '').length;

Just StringB.length is going to give the number of letters in StringB

  • Finally you did not check if their lengths are equal your conditions were just if one is greater than the other. In real life you want your code to be dynamic and work regardless of the users input... if my superhero and sidekick have the same length of names, your code will print out StringF (the Sidekick's got the longest name, it has), also it doesnt say how long the sidekick's name is.

A way to solve it.

let superhero = 'batMan'

console.log(`My favorite superhero's name is ${superhero}`)

let sidekick = 'Robin'
console.log(`The sidekick's name is ${sidekick}`)


if(superhero.length > sidekick.length) {
  console.log(`The Hero's got the longest name, it has ${superhero.length} characters`)
}
else if(sidekick.length > superhero.length){
  console.log(`the Sidekick's got the longest name, it has ${sidekick.length} characters`)
}
else{
  console.log(`wow, they both got equally long names, ${sidekick.length} characters!!`)
}

Initial Task

  • Create a variable hero with the your favorite superhero

  • Console.log My favorite superhero's name is XXXX

  • Create a variable sidekick with another name

  • Console.log The sidekick's name is YYYY

Conditionals

Depending on which name is longer, console.log:

  • The Hero's got the longest name, it has XX characters or the Sidekick's got the longest name, it has XX characters or wow, they both got equally long names, XX characters!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment