Google colabolatoryでは、わざわざHTMLファイルを用意しなくてもJavaScriptを試せる。
【Colab】GooglecolabでJavaScriptを動かそう! - AI Academy Media
アルゴリズムの勉強をJavaScriptでやってみる。
まずは最大値をもとめるアルゴリズムです。
3つの値のうち、最大値を表示するものです。
%%js
const a = 3;
const b = 4;
const c = 1;
let max = a;
if(max < b){
max = b;
}else if(max < c){
max = c;
}
console.log(max);
別解答です。
%%js
const a = 3;
const b = 4;
const c = 1;
function max(x,y,z){
let maxValue = x;
if(maxValue < y){
maxValue = y;
}else if(maxValue < z){
maxValue = z;
}
return maxValue;
}
console.log(max(a,b,c));