Ask coding questions

← Back to all posts
1
New to javascript, not understanding the questions from the assignment, help please.
JordanB12 (0)

I think I understand most of what the question is asking, I just can't seem to figure out what they mean by assign things to other things, or how to do it. I tried looking online, but nothing seems to quite match what I'm trying to do. Or I'm doing it wrong, which is very possible.

function exerciseThree(str){
// In this exercise, you will be given a variable, it will be called: str
// On the next line create a variable called 'length' and using the length property assign the new variable to the length of str
let length = 'length'

// Please write your answer in the line above.
return length;
}

function exerciseFour(num1){
// In this exercise, you will be given a variable, it will be called: num1
// On the next line create a variable called 'rounded'. Call the Math global object's round method, passing it num1, and assign it to the rounded variable.
let rounded = 'rounded'
math.round(num1)

Answered by TheDrone7 (518) [earned 5 cycles]
View Answer
Commentshotnewtop
3
TheDrone7 (518)

It just means assigning values to the variables using the assignment operator(= sign).
Assign blah to that just means.

let that;
that = blah;

Please mark this as the correct answer if it helps.

1
JordanB12 (0)

@TheDrone7
So this is where I'm at with it, and what your saying makes sense, but it seems to want me to assign the variable length to the string 'length', then use that to assign it the length of str. I think the question is just badly written, but maybe I'm just missing something very obvious.

function exerciseThree(str){
// In this exercise, you will be given a variable, it will be called: str
// On the next line create a variable called 'length' and using the length property assign the new variable to the length of str
let length = 'length';
length = str;

// Please write your answer in the line above.
return length;
}

1
JordanB12 (0)

@TheDrone7 I've also tried just
const length = str;

but that also appears to be wrong. It's wanting to return the length, I assume of str, but surely it knows the length of variable str, just by its existence. argh.

1
TheDrone7 (518)

@JordanB12 I'm afraid that what it should actually say according to me is: -
You have a variable named str and you have to create a new variable named length which should store the length of whatever str is.

1
TheDrone7 (518)

@JordanB12 you're close, what you need to do is store the length of str in the variable named length. For example, consider that str is "Hello World", it's a string with 11 characters in it. Then the variable length should hold the value 11. You'll need to figure out how to get the length of str since it won't always be the same thing. I don't think I can simplify the terms even more and answering by providing correct code is against repl talk rules. So that's all the help I can provide. Hope you solve it soon.

1
ash15khng (220)

Do you know how to assign variables?
Use =. For example, let a = "hello" assigns "hello" to the variable a.