Skip to content
Fabian Morón Zirfas edited this page Jun 13, 2025 · 2 revisions
/*
    To keep your code tidy you can put code pieces
    together in a function. You can use them more than one time.
    Like this
    */

main();

// the main code
function main() {
	var a_string = "Uh. I really want to know how many characters are in me!";
	var res = calc_str_length(a_string);
	alert(res);
	var b_string = "lets see how many characters I have!";
	res = calc_str_length(b_string);
	alert(res);
	// you don't need this return thing here
	// but it is cleaner that way
	// also have a look at the ESTK console
	return 0;
}

// the calc function
function calc_str_length(str) {
	var l = str.length;
	return l;
}

Home

Clone this wiki locally