Newbie - custom script not working

I am a newbie , I want to know in which programming language the custom script is written ?
Searched few examples and created some conditional fields , but I am not able to make calculated fields .

Please someone help me ,

I created four custom fields in a doctype , now i want to add the values of the first three fields and display it in the fourth field ? All four fields are in the same doctype . Please help me by giving the syntax and functions to be used .

Below is my script

cur_frm.add_fetch("edger", "blocker", "finisher", "total");
frappe.ui.form.on("Product master", "total", function(frm, doctype, name) {
cur_frm.cscript.custom_validate = function(doc) {

var edger=edger;
var blocker=blocker;
var finisher=finisher;
var total=0;;



why function inside function?


Thank you sir , It worked but i landed into a new problem . I am not able to run more than one custom script in one doctype . Here is my script

function compute(doc, cdt, cdn){
if (doc.upper_die_d1 && doc.upper_die_d2 && doc.upper_die_d3 && doc.lower_die_d1 && doc.lower_die_d2 && doc.lower_die_d3 && doc.total_weight2 && doc.cost_per_kg){
doc.upper_die_weight = doc.upper_die_d1 * doc.upper_die_d2 * doc.upper_die_d3 * 0.000008;
doc.lower_die_weight = doc.lower_die_d1 * doc.lower_die_d2 * doc.lower_die_d3 * 0.000008;
doc.total_weight = doc.lower_die_weight + doc.upper_die_weight;
doc.total_cost = doc.total_weight2 * doc.cost_per_kg;
cur_frm.cscript.custom_upper_die_d1 = compute;
cur_frm.cscript.custom_upper_die_d2 = compute;
cur_frm.cscript.custom_upper_die_d3 = compute;
cur_frm.cscript.custom_lower_die_d1 = compute;
cur_frm.cscript.custom_lower_die_d2 = compute;
cur_frm.cscript.custom_lower_die_d3 = compute;
cur_frm.cscript.custom_total_weight2 = compute;
cur_frm.cscript.custom_cost_per_kg = compute;

function compute(doc, cdt, cdn){
if (doc.tcs && doc.cq){
doc.cpop = doc.tcs / doc.cq;
cur_frm.cscript.custom_tcs = compute;
cur_frm.cscript.custom_cq = compute;

The second script runs properly , but the first script stopped working after entering the second script . please help