I wanted a program that could calculate the slope of any function, that the user inputed, at any certain point.
The glaring issue here is that I've used eval() and that one has to input the functions in javascript format with x as the variable. I know I'm a naive programmer but I just wanted it plain and simple. No text parsing, for now.
I would like suggestions for improvement and maybe even a short bit of code.
On second thought, can eval() actually be made safer somehow?
function calculate_slope(form){
var func, x, slope, first_f_x, second_f_x
x = parseFloat(form.x.value) + 0.0000000001
first_f_x = eval(form.func.value)
x = parseFloat(form.x.value)
second_f_x = eval(form.func.value)
form.slope.value = (first_f_x - second_f_x) / 0.0000000001
}

New Topic/Question
Reply



MultiQuote




|