본문 바로가기

JS/learned_it_today

함수 - return, 계산기

function sayHello(name, age){

return `Hello ${name} you are ${age} years old.`;

}



const greetNicolas = sayHello("Nicolas", 15)



console.log(greetNicolas)​
function sayHello(name, age){

console.log(`Hello ${name} you are ${age} years old.`);

}



sayHello("Yunmi", 15);



console.log("Hi")

 

 

 

 

"hello", name, "you are" 

"hello"+name+"you are"

대신

`hello ${name}`

 

 

 

 

function sayHello(name, age){

console.log(`Hello ${name} you are ${age} years old.`);

}



sayHello("Nicolas", 15);

 

 

 

 

 

 

 

const calculator = {

plus:function(a, b){

return a+b;

},

minus:function(a,b){

return a-b;

},



multiple:function(a,b){

return a*b;

},



divide:function(a,b){

if(b!=0)

return a/b;

else

return "cannot divide by zero"

},

power:function(a,b){

return a**b;

}

};






console.log(calculator.plus(5,5));