+ 2

Why am I having a hard time learning about functions that use parameters??

I'm trying to beat a simple challenge on CodeWars but functions that have parameters are making me bash my face into my keyboard. I understand that a parameter is a variable included into a parameter but i have no clue as to how to define the var and get it to do what I need it to do. It's a level 8 kyu....

1st Apr 2019, 10:21 AM
Jake Serrano
Jake Serrano - avatar
8 Respuestas
+ 5
Well it's something. Here you go: function coolZone(num) { return num * 3; } var threeTimesTen = coolZone(10); To figure out what the last line does, you can do "substitution": Everywhere you see a `num` in the function body, replace it with 10 in your mind. What comes after the `return` is what will be stored in `threeTimesTen`.
1st Apr 2019, 10:46 AM
Schindlabua
Schindlabua - avatar
+ 4
Try finish the python course you are already learning...trust me, everything will be fine
1st Apr 2019, 10:47 AM
Dan Rhamba
Dan Rhamba - avatar
+ 2
hmm, can you write a function that takes a number and returns that number times 3?
1st Apr 2019, 10:28 AM
Schindlabua
Schindlabua - avatar
+ 1
Schindlabua thanks for helping me. I'm going to try practicing this. I think it can't get anymore simple than what you showed me.
1st Apr 2019, 10:53 AM
Jake Serrano
Jake Serrano - avatar
+ 1
ex... function functionName(par1,par2) { this.par1 = par1; this.par2 = par2; return par1*par2; } ex2. function(x,y) { this.x =x; this.y =y; let h= document.getElementById("random"); let i, j, k; return x+y; } yea parameter are like local variables...they can only be used inside the function itself or any inner function that. you can pass arguments into your paraments. and get some results. some simple examples to help out
19th Apr 2019, 8:17 PM
kay cruz
kay cruz - avatar
0
function coolZone(code){ code = 5; coolZone(1 * 3); (coolZone) * 5); } Please forgive me for the above bad attempt at coding...
1st Apr 2019, 10:37 AM
Jake Serrano
Jake Serrano - avatar
0
I was trying to learn Python on here but it seemed like it was counterproductive since i don't have a decent grasp on JS yet.
1st Apr 2019, 10:54 AM
Jake Serrano
Jake Serrano - avatar
0
^^^ that code wouldnt work in js
1st Dec 2019, 3:53 PM
kay cruz
kay cruz - avatar