function play(strat,unit_order_starting_from_top) {
if ('speechSynthesis' in window) {
let top_strat = strat.success.data[unit_order_starting_from_top]
let intro_message = ""
if (unit_order_starting_from_top == 0){
intro_message = "The following is about the top unit present at this location."
}
if (unit_order_starting_from_top == 1){
intro_message = "The following is about the second from the top unit present at this location."
}
let intro = new SpeechSynthesisUtterance(intro_message);
window.speechSynthesis.speak(intro);
let names_of_lith = []
let highest_prop_lith = {"lith":"there's a problem in the code","prop":0}
let names_of_environ = []
let highest_prop_environ = {"environ":"there's a problem in the code","prop":0}
for (let i = 0; i < top_strat.lith.length; i++) {
if (top_strat.lith[i].prop >= highest_prop_lith.prop){
highest_prop_lith.lith = top_strat.lith[i].name
highest_prop_lith.prop = top_strat.lith[i].prop
}
names_of_lith.push(top_strat.lith[i].name)
}
for (let i = 0; i < top_strat.environ.length; i++) {
if (top_strat.environ[i].prop >= highest_prop_environ.prop){
highest_prop_environ.environ = top_strat.environ[i].name
highest_prop_environ.prop = top_strat.environ[i].prop
}
names_of_environ.push(top_strat.environ[i].name)
}
let length_of_lithos = top_strat.lith.length
let working = new SpeechSynthesisUtterance("This unit has "+top_strat.lith.length+" lithologies.");
window.speechSynthesis.speak(working);
let workingAge = new SpeechSynthesisUtterance("The unit's age is between "+Math.round(top_strat.t_age)+" and "+Math.round(top_strat.b_age)+" million of years old.");
window.speechSynthesis.speak(workingAge);
let working4 = new SpeechSynthesisUtterance("The max thickness of this unit near this location is "+ Math.round(top_strat.max_thick)+".");
window.speechSynthesis.speak(working4);
let working_common_lith = new SpeechSynthesisUtterance("The most common lithology at "+Math.round(highest_prop_lith.prop*100)+ " percent of this unit is "+highest_prop_lith.lith+ ". Other lithologies include, "+names_of_lith.toString());
window.speechSynthesis.speak(working_common_lith);
let working_common_environ = new SpeechSynthesisUtterance("The most common depositional environment at "+Math.round(highest_prop_environ.prop*100)+ " percent of this unit is "+highest_prop_environ.environ+ ". Other lithologies include, "+names_of_environ.toString());
window.speechSynthesis.speak(working_common_environ);
}
else{
document.write("Browser not supported")
}
}