The Perform a task Function Exercise Practice
Hey Hayk, I was practicing the functions that perform a task. I learned something new from ai, but wanted your feedback. I learned this from Cursor ai.
There are two, or at least two of the ways they mentioned to me that I can write the function that performs a task. The two ways are the direct action pattern function and the return pattern function.
///////////Return Pattern Function:
function go(home) {
return `I am going ${home}`;
}
go('to the house');
const houses = go('to the house');
console.log(houses);
function age(years) {
return `I am about to be ${years}`;
}
age('42 years old');
const msg = age('42 years old');
console.log(msg);
function message(note) {
return `Take a look at this ${note}`;
}
message('notebook');
const notepad = message('notebook');
console.log(notepad);
function tagname(tagline) {
return `Coding is fun and ${tagline}`;
}
tagname('exciting');
const tag = tagname('exciting');
console.log(tag);
////////////////////////////////////
/////Direct Action Pattern function:
function greet(username) {
console.log('Hello', username);
}
greet('John');
function sayHey(name) {
console.log('Welcome home. We really missed you', name);
}
sayHey('Lucy');
function welcome(teacher) {
console.log('Welcome teacher', teacher);
}
welcome('Rudy');
function Hello(age) {
console.log('My age is ', age);
}
Hello('29 years old');
function show(homework) {
console.log('Show me what assignments you have', homework);
}
show('that your teacher told you to complete');
///////////////////////
I was doing the exercises and practicing the functions that perform a task before I practiced the exercises for the function that return a value. Cursor ai calls the one you was going over in the course the direct action pattern.
Cursor broke down the step by step process on how to do the functions for both of these.
For Return Pattern Function:
Step1 :Write the function and what it will do(with it's parameter in the parenthesis).
Step 2 : Call the function name/keyword with what you want to return.
Step 3 : Create a variable to store the function name/keyword and what you want to return.
Step 4 : Log it in the console.
For Direct Action Pattern:
Step 1 : Write the function and the console.log in it(like Hayk did in the course).
Step 2 : Call the function with what you want to return.
Hayk, did I do these two function exercises right and is what I learned correct from Cursor ai about these 2 ways to write a function that performs a task?
3
14 comments
SeaAmber Silver
6
The Perform a task Function Exercise Practice
Dev Mastery
skool.com/devmastery
Break out the mid-tier developer trap. Get to Senior, fast.
Leaderboard (30-day)
Powered by