What is the best way to update the old string values with the new string values?

function decipher(str) { // YOU DID IT!
  var newString = str.split(" ");

  for(var x = 0; x < newString.length; x++ ){
    for( var y = 0; y < newString[x].length; y++ ){
      if(newString[x].charCodeAt(y) < 78){

        String.fromCharCode(newString[x].charCodeAt(y) + 13);

      }
      else if(newString[x].charCodeAt(y) >= 78){
          String.fromCharCode(newString[x].charCodeAt(y) - 13);
      }
    }
  }
  return newString;
}

// Update the input below to test
decipher("FREE CODE CAMP");

I've successfully translated the original code into actual words, but I'm struggling to replace them with the correct words in the new string. Any assistance would be greatly appreciated.

Answer №1

Here is an example to try out...

function decrypt(str) { // YOU DID IT!    
    var newArray = str.split(" ");   
    var decryptedStr = "";

        for(var i = 0; i < newArray.length; i++ ){   
            for( var j = 0; j < newArray[i].length; j++ ){   
                if(newArray[i].charCodeAt(j) < 78){

                    //String.fromCharCode(newArray[i].charCodeAt(j) + 13);
                    decryptedString = decryptedString + (newArray[i].charCodeAt(j) + 13).toString();
                }   
                else if(newArray[i].charCodeAt(j) >= 78){   
                    //String.fromCharCode(newArray[i].charCodeAt(j) - 13);   
                    decryptedString = decryptedString + (newArray[i].charCodeAt(j) - 13).toString();   
                }   
            }   
        }   
    return newArray;
}

// Modify the inputs below to test
decrypt("SERR PBQR PNZC");

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Customizing jquery-template based on specific field values during rendering

In a separate file named section.htm, I have the following template: <h3>${Name}</h3> {{each Variables}} {{tmpl($data) Type}} ${Type} | ${Name} | ${Value} <br/> {{/each}} I am trying to render different templates based on th ...

React-Bootstrap Popup encounters overlay failure

While using the Tooltip without an OverlayTrigger, I encountered the following error: webpack-internal:///133:33 Warning: Failed prop type: The prop overlay is marked as required in Tooltip, but its value is undefined. The code snippet causing the issu ...

Transferring information from a component that includes slot content to the component within the slot content

This task may seem complex, but it's actually simpler than it sounds. I'm struggling with the correct terminology to enhance the title. I need to transfer data from a component that includes slot content to that slot content component. In partic ...

The implementation of useProxy in puppeteer does not return a valid function or constructor

Currently, I am using puppeteer and attempting to utilize a proxy per page. To achieve this, I am making use of a package called puppeteer-page-proxy. const puppeteer = require('puppeteer'); var useProxy = require('puppeteer-page-proxy&ap ...

Conceal virtual keyboard on mobile when in autocomplete box focus

I would like the keyboard to remain hidden when the autocomplete box is focused or clicked, and only appear when I start typing. The code below currently hides the keyboard when any alphabets or numbers are pressed. However, I want the keyboard to be hidd ...

Load elements beforehand without displaying them using a div

In order to efficiently manipulate my Elements using jQuery and other methods, I am exploring the idea of preloading them all first. One approach I have considered is creating a div with CSS display set to none, and placing all the elements I need for my w ...

Exploring the possibilities of infinite scroll in JavaScript using the Backbone framework

I've been grappling with this problem for three days straight. I've been attempting to incorporate scrolling into my backbone project using the https://github.com/paulirish/infinite-scroll plugin. Despite my best efforts to find a solution throu ...

Design a 3D visualization of a stack using data points in the Three.js platform

I am currently working on developing a web application that aims to generate a 3D model of a gravel pile based on data points captured using a laser device and three.js. However, I have encountered a challenge in creating a hull that accurately represent ...

HTML/JavaScript: Embrace the Power of Dynamic Page

I have a unique element in my HTML code: <image src="http://..." style='...'> Using Python-Flask, I pass on a dynamic source address and save it as window.dynamicEmbedding. Now, during page load, I want to change the image's ...

PHP Error: Attempting to access single values in an invalid way

After setting up an array in my functions.php file to be used on another page, I made sure to return the array and call it on a separate page. Here's what I have: Within my functions.php file: public function getpostcontent($userid){ include(&ap ...

Seeking a regular expression to identify special characters appearing at the beginning of a string

I'm looking to update my current regex pattern to include special characters at the beginning of a string value. Here's what I have right now: /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[!@#$%^&*()_+])[A-Za-z\d][A-Za-z\d!@#$%^&*()_+.]{ ...

Error in AngularJS: Unable to access property 'get' as it is undefined

Upon examining my App, I found that it is structured as follows: var app = angular.module('cockpit', ['tenantService', 'ngMaterial', 'ngMdIcons']); The controller associated with my App appears like this: angula ...

What is the process for activating the currently active tab or link within the MDBNav component of MDBreact?

Here is the code snippet I am working with: import React from "react"; import { BrowserRouter } from 'react-router-dom'; import { MDBNav, MDBNavItem, MDBNavLink } from "mdbreact"; const CustomTabs = props => { return ( <BrowserRouter& ...

A guide to resolving cross-origin resource sharing issues using a reverse proxy

After creating a JavaScript web application for processing documents, I am now looking to integrate with web services like NLTK-server, TIKA-server, and SOLR for further analysis. While I can successfully access the REST endpoints of these services using c ...

Choosing the Best Orthographic Projection for a 1:1 Mapping of Points to SceneKit Positions

Which orthographic projection is required to create a 2D application in SceneKit with a 1:1 ratio of SceneKit points to screen points/pixels? For example, if I want to position an object at (200, 200) on the screen using a SCNVector of (200, 200, 0), what ...

Obtain a collection of keys that share identical values

In my JavaScript code, I have an array of objects structured like this: objArray = [ {"date":"07/19/2017 12:00:00 AM","count":"1000","code":"K100"}, {"date":"07/21/2017 12:00:00 AM","count":"899","code":"C835"}, {"date":"07/23/2017 12:00:00 AM","cou ...

clicking on an element to get its div id

In my code snippet $('.startb').click(function() { var myId = $(this).attr("id"); });, I am already capturing the id "startb1". To also capture the id "test1" from the element with the class "flashObj", all within the same div container "audioCon ...

Exploring a different approach to utilizing Ant Design Table Columns and ColumnGroups

As per the demo on how Ant Design groups columns, tables from Ant Design are typically set up using the following structure, assuming that you have correctly predefined your columns and data: <Table columns={columns} dataSource={data} // .. ...

Did I incorrectly pass headers in SWR?

After taking a break from coding for some time, I'm back to help a friend with a website creation project. However, diving straight into the work, I've encountered an issue with SWR. Challenge The problem I'm facing is related to sending an ...

When an integer array is included as a JSON parameter, it is automatically converted to a string

I need to include an integer array as a request parameter in JSON format. I am accomplishing this using the following method: org.json.JSONObject jsonObject=new org.json.JSONObject(); jsonObject.accumulate("",integerArray); However, when I add it as a pa ...