javascript - how to build a visual representation of a wall and tiles with java script? -


so i've been set task interview i'm struggling finish it. task : build html page can input dimensions (height , width) of set of tiles , input dimensions (height , width) of wall.

the page return number of tiles needed fill wall, give visual representation of wall tiles on it.

so far i've managed easy math work out tiles have no clue start show wall.

<form >     tile dimensions<br />     width: <input type="text" id="tile_width" />cm    height: <input type="text" id="tile_height" />cm     <br />    wall dimensions<br />    width: <input type="text" id="wall_width" />cm    height:<input type="text" id="wall_height" />cm  </form>     <button onclick="tilecalc()" >calculate</button>  <script language="javascript" type="text/javascript"> function tilecalc() {  var tilewidth = document.getelementbyid("tile_width").value;  var tileheight = document.getelementbyid("tile_height").value;  var wallwidth = document.getelementbyid("wall_width").value;  var wallheight = document.getelementbyid("wall_height").value;;  var tilearea = tilewidth * tileheight;  var wallarea = wallwidth * wallheight;  var nooftiles = (wallarea/tilearea);  document.getelementbyid("result").innerhtml="you need " + nooftiles + " tiles"; } </script> 

nothing simpler this. can use for/while-loop iterate on nooftiles , create div each iteration-step:

var tilewidth = 100; var tileheight = 100; var wallwidth = 1000; var wallheight = 1000; var tilearea = tilewidth * tileheight; var wallarea = wallwidth * wallheight; var nooftiles = (wallarea/tilearea);  for(var = 0; < nooftiles; i++) {     var div = document.createelement("div");     div.style.width = tilewidth + "px";     div.style.height = tileheight + "px";     div.innerhtml = i;     document.body.appendchild(div); } 

http://fiddle.jshell.net/vxwsn/1/


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -