Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Crazy Table</title>
- <style type="text/css">
- #count {width: 5em}
- #margin {height: 20em; width: 20em; border: 0.5em solid red}
- #motherTable {width: 100%; height: 100%; border-collapse: collapse; table-layout: fixed}
- #tableSize {width: 3em}
- </style>
- <script type="text/javascript">
- function charCount()
- {
- (document.getElementById("count")).value = (document.getElementById("textArea")).value.length;
- }
- function getRandomColor()
- {
- var R = Math.floor((Math.random() * 255) + 1);
- var G = Math.floor((Math.random() * 255) + 1);
- var B = Math.floor((Math.random() * 255) + 1);
- return "rgb(" + R + ", " + G + ", " + B + ")";
- }
- function changeColor()
- {
- (document.getElementById("textArea")).style.backgroundColor = getRandomColor();
- }
- function findString()
- {
- var fullText = document.getElementById("textArea").value;
- var text = document.getElementById("stringFinder").value;
- var count = 0;
- var end = fullText.length;
- while(end >= text.length)
- {
- fullText = fullText.substring(0, end);
- var occurence = fullText.lastIndexOf(text);
- if(occurence != -1)
- {
- count++;
- end = occurence;
- }
- else
- end--;
- }
- alert(count + " occurences!");
- }
- function isPrime(num)
- {
- if(num <= 1)
- return false;
- if(num == 2)
- return true;
- if(num % 2 == 0)
- return false;
- for(var f = 3, root = Math.sqrt(num); f <= root; f += 2)
- if(num % f == 0)
- return false;
- return true;
- }
- function findPrimaries(num)
- {
- var result = "";
- for(var i = 0; i <= num; i++)
- if(isPrime(i))
- result += i + " ";
- alert(result);
- }
- function primaryNumbers()
- {
- var num = prompt("Enter a number please:");
- findPrimaries(num);
- }
- window.onload = function()
- {
- document.getElementById("line").innerHTML = "This is code generated paragraph";
- }
- function createTable()
- {
- var table = document.getElementById("table");
- var size = +document.getElementById("tableSize").value;
- if(!(size > 0))
- return;
- table.innerHTML = "";
- for(var i = 0; i < size; ++i)
- {
- var row = "<tr>";
- for(var j = 0; j < size; ++j)
- row += "<td></td>";
- table.innerHTML += row + "</tr>"
- }
- }
- var key;
- function animation()
- {
- var bt = document.getElementById("animationButton");
- if(bt.innerHTML == "התחל אנימציה")
- {
- var tableSize = document.getElementById("tableSize");
- if(+tableSize.value <= 0)
- tableSize.value = 1;
- var size = +tableSize.value;
- var step = 1;
- bt.innerHTML = "עצור אנימציה";
- key = setInterval(function()
- {
- if(size >= 10)
- step = -1;
- else if(size <= 1)
- step = 1;
- size += step;
- tableSize.value = size + "";
- createTable();
- }, 200);
- }
- else
- {
- clearInterval(key);
- bt.innerHTML = "התחל אנימציה";
- }
- }
- </script>
- </head>
- <body>
- <table>
- <tr valign="bottom">
- <td rowspan="2"><textarea id="textArea" oninput = "charCount()" rows="10" cols="50" placeholder="Enter text here..."></textarea></td>
- <td>
- <label>Count</label>
- <input id="count" type="number" readonly="readonly"/>
- </td>
- </tr>
- <tr>
- <td><button onclick="changeColor()">שנה צבע</button></td>
- </tr>
- </table>
- <button onclick="findString()">חפש תווים</button>
- <input id="stringFinder" type="text">
- <br><br>
- <button onclick="primaryNumbers()">מספרים ראשוניים</button>
- <br><br><br>
- <div id="line"></div>
- <br>
- <div id="margin">
- <table border="1" id="motherTable">
- <tbody id="table">
- </tbody>
- </table>
- </div>
- <label for="tableSize">גודל הטבלה</label>
- <input id="tableSize" type="number" min="1" max="10" value="1">
- <button onclick="createTable()">צור טבלה</button>
- <button id="animationButton" onclick="animation()">התחל אנימציה</button>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement