Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Find The Length Of A String

Yogi

Coder
Hi,

I've just started to learn JavaScript, being a beginner. In order to qualify myself for the proper boot camp, I must do a kind of online course first and pass some challenges.

I've got a bit stack in a very simple situation.

My problem is:

Create a new variable called stringLength. Use the length property to write an expression that evaluates to the length of the variable provided and assign it to the variable you just created.

I've been given:
JavaScript:
const word = 'N****coders'

And I've tried to solve it like that:
JavaScript:
const word = 'N****coders'
const stringLenght = string.lenght
Getting the answer: Check whether you are correctly using the .length property

Maybe for an experience coder this is something very simple but I'm only at the beginning of this road trying to learn.

Many thanks for any help I can get!
 
if you want length of string you will need to change string.length to word.length. Word has the characters.
Basic example
JavaScript:
const word = 'some word'
const stringlength = word.length

console.log('String length is ' + stringlength + ' charcters long.')

output
Code:
String length is 9 charcters long.
 
Many thanks mate! I really appreciate your help!
Your previos answer helped me to fix my next problem:
  • Create a new variable twiceTheCarrots. Assign to it a value equal to double the value of carrots.
  • Create a new variable characterCount that will store the length of the text on the board.
  • Create a variable called shoutingText and assign it text of the board, but with all characters as capital letters.
JavaScript:
function lindasBounty() {
    const carrots = 239;
    const boardText = 'Buy our carrots! Sale Now On!';
    // Do not change code above this line
    // Do not change code below this line
    const twiceTheCarrots = 2 * carrots
    const characterCount = boardText.length
    const shoutingText = boardText.toUpperCase()
    return {
        numberOfCarrots: twiceTheCarrots,
        boardSize: characterCount,
        advert: shoutingText
    };
}

I've resolved it well!

Many thanks!
 
Good that it's already solved. I have two general tips for you:
  • Mind your spelling. string.lenght is wrong !
  • When something does not work, always check the Console output in the Debugger (F12). You should have seen this error loud and clear.
 
Good that it's already solved. I have two general tips for you:
  • Mind your spelling. string.lenght is wrong !
  • When something does not work, always check the Console output in the Debugger (F12). You should have seen this error loud and clear.

Hi,

Many thanks for the tips! I didn't observed the wrong spelling.

I'm doing this JavaScript course online, so, I have to write the answer/solved code in a browser app, where is checked by their system. It is not showing me where the problem is.
Can I ask as an advice please, what app should I use? Some people recommend Visual Studio, or Visual Studio Code. I'm using a laptop 6 gb ram, with Ubuntu Studio OS.
Only after I'll finis it, final challenge included, I'll start my proper boot camp.
 
I admit having trouble with spelling that particular word too 😁
But do I understand correctly that you are submitting code without it first being tested ? That seems a dangerous game.
I can't really advise on the best tool to use, as I habitually only use only a text editor and the Chrome browser. If you are doing just Javascript, without HTML/CSS, you could install Node.js. Or, indeed, Visual Studio Code (which I have heard good things about but have not really made friends with yet). Another option would be JsFiddle.
 
I would recommend visual studio code. You will need Node.js installed as visual studio uses it. I use Ubuntu and run visual studio for all the coding I do. Python, javascript, php, and c languages. Even has an html view (which I don't really like that well). I usually just open it in the browser to view the pages I'm working on.
 
I admit having trouble with spelling that particular word too 😁
But do I understand correctly that you are submitting code without it first being tested ? That seems a dangerous game.
I can't really advise on the best tool to use, as I habitually only use only a text editor and the Chrome browser. If you are doing just Javascript, without HTML/CSS, you could install Node.js. Or, indeed, Visual Studio Code (which I have heard good things about but have not really made friends with yet). Another option would be JsFiddle.
Yeah, sorry for my spelling, English is not my first language but in the last 5 years and half I've been leaving in the UK and I had to learn it from scratch :) I'm still struggling, but a good will to learn it's everything we need when we want to do something. Isn't it?

Yes, for the moment, only JavaScript Basics, I don't know how will be later.

I would recommend visual studio code. You will need Node.js installed as visual studio uses it. I use Ubuntu and run visual studio for all the coding I do. Python, javascript, php, and c languages. Even has an html view (which I don't really like that well). I usually just open it in the browser to view the pages I'm working on.
Many thanks for all of the advises as well! I think I'll go for Visual Studio Code, with node.js installed.
About the OS.. I'm using Ubuntu Studio because its very well configured for audio video production. What do you think, should be better to reinstall Ubuntu desktop / plain? The official one.
One of our 13 weeks boot camp requirement is to have installed Ubuntu, but they not specifying anything about not allowing Ubuntu flavors. Betwen two of them it's some small difference but both of them have got the same core, structure and commands.

Anyway, today I've got invite on their Slack channel as well. I think this will help me a lot to figure out future problems because I'll be able to speak with our tutor and other colleagues.

Many thanks for all of your help guys! :coffee: :coffee:
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom