Intermediate Algorithm Scripting - Convert HTML Entities

Tell us what’s happening:
ik im in the last of the intermediate probs and difficulties WILL arise… but im also stumped here… a bit
Your code so far

function convertHTML(str) {
  let apost = "<"
  let quote = """
  let more = ">"
  let less = "<"
  let amp = "&"
 
  let charArr = str.split("")
  
  //console.log(charArr)

  for (let i = 0; i < charArr.length; i += 1){
    let instance = charArr[i]
    switch(instance){
      case "&":
      instance = amp;
      console.log(amp)
      break;

      case "<":
      instance = less;
      break;

      case ">":
      instance = more;
      break;

      case "'":
      instance = apost;
      break;

      case '"':
      instance = quote;
      break;
    }
  }

  charArr = charArr.join("");
  console.log(charArr)
}

console.log(convertHTML("Dolce & Gabbana")
)

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36

Challenge: Intermediate Algorithm Scripting - Convert HTML Entities

Link to the challenge:

Two things:

  • I don’t see where you are returning the converted string.
  • I don’t see where you are building a new string that will include the converted characters.

i see that im not returning the string
(:face_with_monocle::confounded: :dizzy_face: :face_with_spiral_eyes: :innocent: :joy::bowing_man: :bowing_man: )
buuuuttt…

???

This would work if you converted the elements in charArr before joining it into a string, but I don’t see where you are doing that.

i thought that was a mechanic
what was under the hood of a switch statement

and this is what im grabbing at as i loop through charArr…
?

This copies the current value at charArr[i] into the variable instance, but anything you do to instance after that only affects the variable instance, it does not affect the original value in charArr[i] in any way.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.