#I just started using javascript. This is not working as intended, is there mistakes?

49 messages · Page 1 of 1 (latest)

plain anchor
#

I just started using javascript. This is not working as intended, is there mistakes?

fathom compass
#

?var

#

(Never use var)

#

You shouldn’t be declaring/assigning those variables at the top of the function. Use the parameters.

plain anchor
#

You see i am not understanding that. Can you help me?

#

Sorry the var is being used in my school examples. Should i be using Let?

fathom compass
#

Or const, yes.

#

#faq to learn modern JS. var is a relic of the past. Your teacher is out-dated.

plain anchor
#

I will let him know lol. thank you

#

ugh this stuff gives me headaches

#

so

#

can you give me an example of "use the parameters"

fathom compass
#

calcFunc(10, 20, 30)

plain anchor
#

ohhhhhhh

#

i am a idiot

#

thank you

#

quick question @fathom compass

#

is 10 not a number in javascript

fathom compass
#

it is

plain anchor
#

it is saying Unexpect number syntax erro

fathom compass
#

show your new code

plain anchor
#
function calcFunc(10,20,30) { 
let a *= 10 
return a
let b -=20
return b 
let c = b + 30
return c 
console.log(c)
} 
module.exports = { calcFunc }

fathom compass
#

oh I bet you changed the function declaration instead of calling the funciton with those values

#

ya 😄

#
function calcFunc (num1, num2, num3) {

that part was correct.. you are defininig your function here.. after defining it, you need to call it

#

I suggest you read the link I pasted above

plain anchor
#

rip my soul

#

okay so what you are saying is to keep this js function calcFunc (num1,num2,num3) {

#

then i need to define js let num1 = 10; let num2 = 20; let num3 = 30;

fathom compass
#

no

plain anchor
#

python is way easier haha

fathom compass
#

fairly sure functions work the same in python

#

you define a function:

function myFunc (parameter1, parameter2, parameter3) {
  return parameter1 + parameter2 + paramater3;
}

then you actually call that function:

myFunc(10, 20, 30);
#

if you read the link, it'll all make sense 🙃

plain anchor
#

oh

#

i see

plain anchor
#

Hey I really appreciate the help. even though its all basic. I did end up getting the correct answer

#

What i don't get is why my teacher is using broken terms that are outdated

#

ugh

fathom compass
#

many teachers do

#

they learned a long time ago and are too lazy to update

plain anchor
#

i used js let

#

it amazing

#

but like the lesson was teaching in var

fathom compass
#

var works, it's just a bad habit to get into. eventually it'll cause you problems

plain anchor
#

That is a huge security risk wtf

#

Imma have a talk with the professor