Hallo i am trying to caclulate a variable MedOC3 and NDWI. Then i want to do an if then else
and return the result of MedOC3 (when NDWI>=0) . I am trying to implement the following code but it doesn t work.

var R_443_560=B01/B03
var R_490_560=B02/B03
var MBR=Math.log10(Math.max(R_443_560,R_490_560))
var NDWI=(B03-B08)/(B03+B08)
if NDWI>=0 {
MedOC3=Math.pow(10,(0.38-3.688MBR+1.036MBR2+1.616*MBR3+1.328*MBR**4))
}
return [MedOC3]

The concept is just fine, but there are quite a few errors in the script.
This should work:

var R_443_560=B01/B03
var R_490_560=B02/B03
var MBR=Math.log10(Math.max(R_443_560,R_490_560))
var NDWI=(B03-B08)/(B03+B08)
var MedOC3=0
if (NDWI>=0) {
MedOC3=Math.pow(10,(0.38-3.688*MBR+1.036*MBR*2+1.616*MBR*3+1.328*MBR*4))
}
return [MedOC3]

Thanks for your reply. Is it possible to have NaN value where NDWI<0 instead of zero?
Also i would like to use a visualization for the MedOC3 variable such as ColorGradientVisualizer.createBlueRed(minVal, maxVal) how i can do that?
Thanks in adavance.

For blue/red you can do something along these lines (configuring min/max appropriately):

var R_443_560=B01/B03
var R_490_560=B02/B03
var MBR=Math.log10(Math.max(R_443_560,R_490_560))
var NDWI=(B03-B08)/(B03+B08)
var MedOC3=0
if (NDWI>=0) {
MedOC3=Math.pow(10,(0.38-3.688*MBR+1.036*MBR*2+1.616*MBR*3+1.328*MBR*4))
}
let minVal = 0;
let maxVal = 10.0;
let viz = ColorGradientVisualizer.createBlueRed();
return viz.process(MedOC3);

Thank you for your answers. Is it possible to use a visualizer such as ColorGradientVisualizer.createWhiteGreen() but use logarithmic scale instead of linear?