JavaScript Trying to reconvert this caesar cipher arr into characters via .charCodeAt in javascript

I'm working on a Caesar cipher problem and have been trucking away but definitely am stuck trying to reconvert this array back into characters.

I tried things like:

document.write(eval('String.fromCharCode('++')'));

and

document.write(String.fromCharCode.apply(null, solved));

and several others with no luck. Any thoughts? I'd really like to avoid going back to the drawing board since this is so close...

Thanks for looking!

function rot13(str) { // LBH QVQ VG!
  var solved = [];
  var arr = str.split("");
  for (var i=0; i<arr.length; i++) {
       solved.push(arr[i].charCodeAt(0));    
    if (solved[i]>65 && solved[i]<91){
       solved[i]-=13;
    }
     String.fromCharCode(solved[i]);
}
  
return solved.join("");}

rot13("SERR PBQR PNZC");
Answer:1

You can't subtract 13 unconditionally: you have to check to see if the code point is below 78 or not. (if it's below 78, then you need to add 13 instead of subtract, or you'll get incorrect characters at the end)

document.write is document.wrong. Use something more modern and less prone to doing confusing things. This function tries to write to the current document. If the document has already been processed, the document will be replaced with a blank one with your argument. You don't want that; use the proper DOM methods instead. (don't use eval either)

You're doing

String.fromCharCode(solved[i]);

but that's a standalone line which doesn't do anything - you probably meant to assign its result to solved[i].

To avoid confusing yourself, probably don't push to the solved array until you actually have a solved character.

function rot13(str) {
  const solved = [];
  const arr = str.split("");
  for (let i = 0; i < arr.length; i++) {
    const initialCharCode = arr[i].charCodeAt(0);
    if (initialCharCode > 65 && initialCharCode < 91) {
      const rotCode = initialCharCode < 78 ? initialCharCode + 13 : initialCharCode - 13;
      solved.push(String.fromCharCode(rotCode));
    } else {
      solved.push(String.fromCharCode(initialCharCode));
    }
  }
  return solved.join("");
}

console.log(rot13("SERR PBQR PNZC"));
Answer:2

I have an json data having property attributes.data. When I console.log(attributes.data) this value I get the result {"uid" : 1} I want to convert this to an array. i.e {"uid" : 1} and so on I want to ...

I have an json data having property attributes.data. When I console.log(attributes.data) this value I get the result {"uid" : 1} I want to convert this to an array. i.e {"uid" : 1} and so on I want to ...

  1. convert object array to string array
  2. convert object array to int array
  3. convert object array to list
  4. convert object array to string array c#
  5. convert object array to string array java
  6. convert object array to string array javascript
  7. convert object array to list c#
  8. convert object array to string array powershell
  9. convert object array to array javascript
  10. convert object array to json javascript
  11. convert object array to int array c#
  12. convert object array to double array java
  13. convert object array to float array python
  14. convert object array to arraylist java
  15. convert object array to byte array c#
  16. convert object array to string array python
  17. convert object array to json java
  18. convert object array to primitive array java
  19. convert object array to string array typescript
  20. convert object array to char array in java

I am using chromedriver and I have the following webpage source: <form id="stepLinksForm" name="stepLinksForm" method="POST" target="mainFrame"> <ul> <li> <a href="...

I am using chromedriver and I have the following webpage source: <form id="stepLinksForm" name="stepLinksForm" method="POST" target="mainFrame"> <ul> <li> <a href="...

  1. python selenium click button
  2. python selenium click element
  3. python selenium click link
  4. python selenium click href
  5. python selenium click button by text
  6. python selenium click checkbox
  7. python selenium click radio button
  8. python selenium click not working
  9. python selenium click coordinates
  10. python selenium click and hold
  11. python selenium click link by text
  12. python selenium click enter
  13. python selenium click intercepted
  14. python selenium click hidden button
  15. python selenium click javascript link
  16. python selenium click element not interactable
  17. python selenium click javascript button
  18. python selenium click tab
  19. python selenium click link in table
  20. python selenium click next button

I have a transition set: element.one("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd", function(){ scrollActive = false; }).css({ '-webkit-transform': '' + prop + '(' + ...

I have a transition set: element.one("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd", function(){ scrollActive = false; }).css({ '-webkit-transform': '' + prop + '(' + ...

I'm trying to convert svg to canvas using the canvg js lib. The original svg contains a rect which has a fill attribute of url to a svg pattern. When I convert the svg to canvas using canvg: canvg(...

I'm trying to convert svg to canvas using the canvg js lib. The original svg contains a rect which has a fill attribute of url to a svg pattern. When I convert the svg to canvas using canvg: canvg(...