I am having trouble with Javascript?

I am having trouble with Javascript?
0

#1

I do not know what to do… I am completely lost. Can someone please help me get into the right direction with this? My instructor is no help to me. There is no tutoring available. I have tried everything I could. Can someone help point my in the right direction please?

Create a function called convertStringToArray that accepts a string and returns an array of numbers. The input format will be “1 2 3 4 5” and you should return [1, 2, 3, 4, 5]. You will have lots of error checking and recovery in this function

Create a function called triple04 that accepts a number and returns three times that number


#2

Do u first resemble string in array and.then sum all digits and the multiple by three, if so here u have all that mix in one function, i find useful to u resemble.this into two function

function mix(str){

    return str.split(" ").reduce(function(base, curr) {
        return base + (+curr);
     }, 0) * 3;
}

also can u try do the thing for.checking for errorsand recovery, and.then if u are stuck i can help


#3

How do I get it to output on html? I am having difficulty making it go out on an html page.


#4


These are the directions. Is there any way you could add me on something to help me with all of this? I am just so lost.


#6

Yes it is homework for my college that I am struggling with. No instructor help and no tutors. I need to be pushed into the correct direction.


#8

It is not cheating if you do not understand the material or how to start it. I did everything I could possibly do. Trust me… I know what all that stuff is. Would I be able to get some help from you?


#9

You should probably make it clear that you are being graded on assignment when you ask for help. Maybe you could describe how you are thinking about approaching this problem (i.e. pseudocode). After that you could as for specific help with portions you don’t know how to code.

The problem here is that you may get very specific, or even complete, answers to your questions.


#10

Hi @ToniG2262!

Firstly, welcome to the forums. While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too. Some of what you are asking is pretty trivial in the Free Code Camp context, so you might find that if you’re not getting the instruction and material you need in your current studies, the FCC curriculum will really help you get up to speed. At a modest guess I’d say investing a 4-5 hours working through the curriculum here will really pay off. You can find the curriculum at http://freecodecamp.com.

With your current questions, we don’t have enough context to know what you already know or don’t know, so it is impossible to guide you without just telling you the answer (which we won’t do).

It is pretty typical on here for people to share a codepen / jsfiddle example of what they have tried so that anyone helping has more of an idea of what help is actually helpful.

Please provide some example of what you’ve tried and I’m sure you’ll get more help.

(You can create a codepen accout here: http://codepen.io and you should find that it’s pretty quick to get up and running, but if not, just @ mention me and I’ll try to help out).


#11

Hey thanks Jackson!
Right now I am trying to Create a function called convertStringToArray that accepts a string and returns an array of numbers. The input format will be “1 2 3 4 5” and you should return [1, 2, 3, 4, 5]. You will have lots of error checking and recovery in this function.
Would this be somewhat in the correct direction? http://codepen.io/anon/pen/LROWXL


#12

It looks like you have some of the right ideas for this kind of task, but I think you’ve misinterpreted your instructions a little. You’re instructed that you’ll receive a string like this: '1 2 3 4 5' but your current work seems to be dealing with an odd string that contains an array of single digit strings: '["1", "2", "3", "4","5"]'

Those strings are not the same, so try working with the first style instead.

Also, it’s asking you to consider error checking. So, imagine this is a form on a website and users can input any string. What will your program ideally do if someone enters the string banana instead of a space-separated list of numbers? Think about how you might add that checking to your program.


#13

So make it so I can type stuff in a textbox and have it come out like that? @JacksonBates


#14

One of the later tasks in the screenshot you posted has you build out that part of it, but for now you just want to focus on making a function that can parse that string correctly and return the correct output.

In fact, the instructions for this part of the task (accept a string, return an array) doesn’t even say you need to print the output to the screen. The function only needs to return the array.

Very simply, you want something like:

function convertStringToArray(string) {
  // Do some magic to string
  return array;
}

#15

So in the middle there I need to make it put out a list of numbers pretty much? @JacksonBates btw thanks for helping me so far!


#16

http://codepen.io/anon/pen/LROWXL how does this look @JacksonBates


#17

For little snippets like that you can just post them here in backticks / code fences (link), like this:

function convertStringToArray(string) {
  var stringToProcess = "1,2,3,4,5";
  return array;
}

A couple of things to be aware of…

The convertStringToArray function accepts an argument called string. So you might run it like this: convertStringToArray('1 2 3 4 5') and want it to return [1,2,3,4,5].

That means you don’t need to set another variable inside the function called stringToProcess. Instead, what you need to do is take the variable string that is passed in as the argument and do something to it so it becomes the array you want.

In the little snippet I wrote, I mentioned array as a thing to be returned, but I never actually set that variable anywhere. So you can either set the array variable to something based on whatever you do to the string variable, or you can skip the array variable all together and just return the method that manipulates the string. (That’s a little wordy - sorry if it’s not clear).

Now, what you do to the string is the key to this task. In javascript, different data types have different methods which can be called on them. Essentially these are mini-functions built in to the data type. For example, arrays have a method called .reverse(), which means if I do this [1,2,3,4,5].reverse() it returns [5,4,3,2,1].

You want a string method that will handle your '1 2 3 4 5' string.

You can find string methods here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

If MDN is a little too hard to handle (it’s not for the faint-hearted!), you can see a more beginner friendly version of these docs here: http://www.w3schools.com/js/js_string_methods.asp