Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6109449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:24:21+00:00 2026-05-23T14:24:21+00:00

I’m having a short 2 character string being sent from C++ to my Javascript

  • 0

I’m having a short 2 character string being sent from C++ to my Javascript (using Awesomium). I know for a fact that the string will either be “L1”, “G1”, “P1”, or “D1”. These are initials.

What I am trying to do is having a text div display the full name of the initial sent in, for example, if “L1” is sent, then “Limes” would appear on the screen, or if “G1” was sent in, “Grapes” would appear.

I’ve tried to remove the last character from the string, then check with if statements that the letter matches with one of the four. I then set the div’s text using $('#div').html("text to be inserted");

For some reason, the code automatically displays the last if statement’s contents, whether or not that is the correct string.

JS:

function showStats(job)
{
   $('#jobHat').css("hat-image", "url(images/"+job+"Hat.png)");

   var jobInitial = job.slice(0, -1); 
   if(jobInitial = "L")
   {
        $('#playerJobText').html("Landman");
   }
   if(jobInitial = "G")
   {
        $('#playerJobText').html("Geologist");
   }
   if(jobInitial = "P")
   {
        $('#playerJobText').html("Petroleum Engineer");
   }
   if(jobInitial = "D")
   {
        $('#playerJobText').html("Drilling Engineer");
   } 

HTML:

<div id ="playerJobText"></div>

CSS:

#playerJobText
{
   width: 200px;
   height: 50px;
   position: absolute;
   font-weight: bold;
   text-align:center;
   top: 32.5%;
   left: 19%;
   font-size: 100%;
   font-style: normal;
   color: black;
   z-index: 50;
}

I include the jobHat segment in the JS code to show an area where the “L1”, “G1”, etc. string works as it should. The image file name is replaced by the string, which shows different images I have, as those images are named L1Hat.png, G1Hat.png, etc.

So what is wrong with the way I’m trying to check the first letter of the string to replace a div’s text?

EDIT I had tried the double == and then the triple === but there was still no results. I put the single = in for this example as it’s what I’m most familiar with, but I’m glad I did so I could get the reminder from you all that == or === is better for this occasion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:24:22+00:00Added an answer on May 23, 2026 at 2:24 pm

    As others have mentioned, you were assigning rather than testing for equality.

    In any event, this code below is simpler and avoids a lot of repetition:

    function showStats(job)
    {
       $('#jobHat').css("hat-image", "url(images/"+job+"Hat.png)");
    
       var initial = job[0];  // or job.substring(0, 1);
       var title = ({
           L: 'Landman',
           G: 'Geologist',
           P: 'Petroleum Engineer',
           D: 'Drilling Engineer'
       })[initial];
    
       $('#playerJobText').text(title);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.