Message from JavaScript discussions

January 2017

— Show us some code m8

— 

Var draw = function(){

//set variable for canvas to draw object
var canvas = "";


var gunung = function (tingkat){
canvas += "/"; //awal gunung
for (var x = 0 ;x < tingkat; x++)
canvas += "-"; //panjang kawah

canvas += "\\"; //akhir dari gunung

}

var data_function = [
function tembok(size) {
canvas += "[";
for (var x = 0;x < size;x++){
canvas += "x";
}
canvas += "]";
},
function jalan(panjang){
for (var x = 0; x < panjang ; x++)
canvas += "_";
}

]

for (var x = 0; x < 3; x++){
var rand_num = Number(Math.floor(Math.random() * 3));
data_function[rand_num](Math.floor(Math.random() * 7));
console.log(rand_num);
}

return canvas;
}

console.log(draw());

— Error line?

— When i input math random for data_function object

— Meh where did you find this code?

— That's not how objects work

— So what's wrong?

— Can you explain this, my friend?

— Everything? 😂

— 😂

— You have to define it kind of
var draw_obj = {
canvas: "",
data_thing_1: function () {...},
data_thing_2: ...
}

Message permanent page

— That's an object