Need help with my coding for a simple logarithm calculation


I have two input fields and one text field for output. and this is the code I tried
export function spl_click ( event ) {
let spl = Number ( $w ( ‘#spl’ ). value );
let distance = Number ( $w ( ‘#distance’ ). value );

function getBaseLog ( x , y ) {
return Math . log ( y ) / Math . log ( x );
}

let answer =( spl - 20 *( getBaseLog ( 10 , ( distance / 1 )));
$w ( ‘#text7’ ). text = answer ;
}

The error is

Well before i start to retype all your code from a pic (which was surely not the aim of my day xD–> next time please use → CODE in CODE-BLOCK to show your code → then your code is selectable and a COPY&PASTE is possible).
And someone who tries to help you, can save some time :wink:

Well, first try to solve your problem by your own. How?
Take a look onto the suggested informations in the info-panel.

IT’S RECCOMENDED TO USE A NEW VARIABLE, SUCH AS →

let xxx = 

Not sure if this will work, but try to follow the instructions…

Here your return-function…

function getBaseLog (x,y){
	return (Math.log(y)/Math.log(x))
}

Now trying the same with…suggested info…

function getBaseLog (x,y){
	let mySuggestedVariable1 = x;
	let mySuggestedVariable2 = y;
	let myResult = Math.log(y)/Math.log(x)
	return (myResult)
}
let answer = (spl-20*(getBaseLog(10, distance/1)));
$w('#text7).text = answer;

But wait! What kind of type is your → “answer” ??? —> NUMBER?
console.log(typeof answer) —> STRING ???

And you try to put a → NUMBER ← into a → TEXT <—

TEXT = STRING ??? / NUMBER = TEXT ??? / STRING=NUMBER???
Already confused? :grin:

Bananas are not equal to apples, right? :wink:

Hi Velo,
Thank you for the info. The code was copy pasted in between the pictures :wink:
Right! bananas not equal to apple. but consider me as a new born for my silly questions. At the moment bananas and apples looks the same to me :grin:
I tried the following and couldn’t able to figure it out
$w ( '#text7 ). value = answer ;
changed the field to number
$w ( '#input18 ).value = answer ;
what should i use

No problem! For me bananas were also = apples when i started my coding adventure. :wink:

You can always inspect/analyse/investigate your own code, by using → CONSOLE.
Place more console-logs on almost every code-line to see what and when actions happens.

You can use → console.log(typeof xxxx) → to show the current TYPE of an output/input

You can change from STRING TO NUMBER → myNumber = Number(myString);
You can change from NUMBER to STRING —> myString = String(myNumber);

Do you AWAIT the results? → ASYNC-AWAIT

EDIT: Yeah, you are right, I was blind and did not see the CODE --< because it was not set into code-blocks. However → next time use CODE-BLOCKs, then such misstakes will not happen again xD :sweat_smile:

Take a look onto J.D. answer → a code in CODE-BLOCKs :wink:

$w('#input7').value= answer.toString();

@russian-dima Yes, it worked Thanks!