Can i convert math.js object into JavaScript function? [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm developing simple js neural network and need to create javascript function (derivative of entered by user) before learning starts.
I know about evaluate(), but i think it'll be slowly than simple function.
That is what i want:
const derivative = math.derivative('x^2/sin(2x)', 'x');
const derivative_func = derivative.please_stay_func();
...
while(1) alert(derivate_func(12)) //:) alert result of (2 * 12 * Math.sin(2*12) - 2 * Math.pow(12, 2) * Math.cos(2*12)) / Math.pow(sin(2*12), 2)
Is it real? And maybe i'm not right about speed. Maybe there is some better ways - write here.

i am on mobile, please edit this
maybe this is want you want to do
const countThings = (customValue) ==>{
let x = 'x^2/sin(x)';
let y = 'x';
x = math.parse(x)
y = math.parse(y)
return math.derivative(x, y).evaluate({x:customValue});}
console.log(countThings(12))
and don't do while(1) alert because it will keep alerting

Related

How to separate a value from a class [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to attempt to get a value from a site and calculate it.
At the moment when entering the command
document.getElementById("txtTehtav")
I recieve the answer along the lines of
<a class="thrida" id="txtTehtav" name="txtTehtav">3x3=</a>
My goal would be to separate the value (3x3) into X and Y (X x Y)
How would I be able to accomplish that?
Any help is appreciated.
const textValue = document.getElementById("txtTehtav").innerText; // Will return 3x3=
const [x, y] = textValue.substr(0, textValue.length - 1).split('x').map((n) => parseInt(n))
const muliplication = x*y;
Try this, you will get the text
document.getElementById("txtTehtav").textContent

I would like to find out how to get the remaining points a user needs to level up [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Sorry, I'm really bad at math and I also don't know the English terms so I really don't know how to ask this question properly.
I'm using this to calculate a users level
const curLevel = Math.floor(0.2 * Math.sqrt(score.points));
I would like to find out how to get the remaining points a user needs to level up. I didn't really try anything yet because I have no idea where to begin, might even be something super simple...
You can find the number of points needed to reach the next integer level by solving for points in the equation curLevel + 1 = 0.2 * Math.sqrt(nextLevelPoint).
You get that you can calculate the total points needed for the next level with:
let nextLevelPoint = Math.pow(5*curLevel + 5, 2)
Subtract score.point from this nextLevelPoint and you get the remaining points a user needs to level up.

What is an example of a "custom function" and "recursion" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have been asked to show I have used these processes in my program but from looking up the definitions, I don't know what they mean. I am confident my program is complicated enough that it uses these processes, but I don't know exactly what they are. What would be an example of these processes used in javascript?
Unsure what you mean by custom function - but recursion is just a function that calls itself.
Example of recursion
countNumTimesToZero = (myNum, count = 0) => {
if (myNum - 1 === 0) return count + 1;
return countNumTimesToZero(myNum - 1, count + 1);
}

Integer comparison within score board app, score difference equal two [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I'm writting an score board app.
Got two integers, i need to compare them, for example
to know when game should be ended, eg. score = 20:22, 24:26 (score difference to end the game should be equal to two)
How i can make such comparison with js?
You can use split() method to separate scores into two different elements, and then afterwards just compare them.
function isGameOver(score, differenceToWin) {
var scoreArray = score.split(":");
return Math.abs(scoreArray[0] - scoreArray[1]) > differenceToWin;
}
isGameOver('24:26', 2)
EDIT: In case you only need to compare two integers, go ahead and use only the return statement line:
var score1 = 24;
var score2 = 26;
var differenceToWin = 2;
var isGameOver = Math.abs(score1 - score2) > differenceToWin;

How to ask in Javascript? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to write a line of code which asks a question and the user has to enter a number. The number is then stored as a variable and used throughout the rest of the script. Such as:
fit1 = "What is your fitness level?"
level = the number the user had entered
something like that. Can't really explain it properly
P.S. I'm writing my code out in gedit because thats what my uni uses.
You can use a prompt like shown below:
var n = prompt("Fitness level");
console.log(n);
window.level = window.prompt('What is my fitness level?');
console.log(window.level); //save in glonal space of window
You can use the Prompt command, and cast the string answer to type number :
var number = parseInt(prompt('Give me a number', '0'));
alert('You said: ' + number);

Categories

Resources