FAQ: Functions - Calling a Function

Placing a for loop inside the fucntion should do it:

function sayThanks() {
for (var i = 0; i < 4; i++) {
console.log('Thank you for your purchase! We appreciate your business. ')
}
};
sayThanks();

not sure whether there is a different meaning to it or else I misunderstood something… In calling a function - in the description the “Identifier” is called greetWorld(); yet below, still describing it explains the function getGreeting() …
I think it should be corrected as otherwise it is misleading.

Could anyone explain why this code does not call the ‘inner’ function I’ve passed as an argument to the ‘outer’ function twice? The output to the console is the inner function called once, and the console.log statement I put at the end to test if the outer function was being exited as a result of the inner function being called once.

function sayThanks() {
console.log(‘Thank you for your purchase! We appreciate your business.’);
}

function twoTimes(func) {
func;
func;
console.log(“Why doesn’t this function execute every line?”);
}

twoTimes(sayThanks());

OUTPUT -
Thank you for your purchase! We appreciate your business.
Why doesn’t this function execute every line?

I did this and it worked.

function sayThanks() { console.log('Thank you for your purchase! We appreciate your business.'); } for (let i = 0; i < 3; i++) { sayThanks() } function sayFive() { sayThanks(); sayThanks(); sayThanks(); sayThanks(); sayThanks(); } sayFive();
1 Like

function sayThanks(){

console.log(‘Thank you for your purchase! We appreciate your business.’);

}
Can we use .repeat(3)