// каждое задание вынесено в отдельную функцию дабы избежать конфликтов пространства имен (namespace)
/* обход проблемы с document . write, используем innerHTML */
function write(text, style) {
var el = document.getElementById("doc");
var styled = text;
switch (style) {
case "h1":
styled = "<h1>" + text + "</h1>";
break;
case "h2":
styled = "<h2>" + text + "</h2>";
break;
default:
styled = "<p>" + text + "</p>";
}
el.innerHTML += styled;
}
function writeln(text) {
var el = document.getElementById("monospace");
el.innerHTML += text + "<br />";
}
// данная функция создает HTML таблицу из многомерного массива
function stringTable(arr) {
if (!"length" in arr) {
return "incorrectParameters";
}
var table = "<table border='1'>";
for (var i = 0; i < arr.length; i++) {
table += "<tr>";
for (var j = 0; j < arr[i].length; j++) {
table += "<td>" + arr[i][j] + "</td>";
}
table += "</tr>"
}
return table + "</table>";
}
/*
https://www.dropbox.com/s/p2a8lx4n9hioz5j/JavaScript%20%232%20%D0%9C%D0%B0%D1%81%D0%B8%D0%B2%D0%B8.docx?dl=0
*/
/*
1. Масив вигляду [[2,5,6],[7,3,9],[3,2,6]] потрібно вивести в зручному для людини вигляді
*/
function task1() {
var arr = [
[2, 5, 6],
[7, 3, 9],
[3, 2, 6]
];
write(stringTable(arr));
}
/*
2. Створити масив розміром N елментів, заповинити його випадковими цілими значеннями.
а) мінімальний елемент;
б) максимальний елемент;
в) вивести всі парні елементи;
г) вивести всі не парні елементи;
ґ) кількість нулів;
д) суму всіх елементів;
е) середнє арифметичне.
*/
function makeArray(size, max) {
if (!max) {
max = 10;
}
var arr = [];
for (var i = 0; i < size; i++) {
arr[i] = Math.round(Math.random() * max * 2) - max;
}
return arr;
}
// matrix - array of arrays
function makeMatrix(size, max) {
if (!max) {
max = 10;
}
var arr = [];
for (var i = 0; i < size; i++) {
arr[i] = makeArray(size, max);
}
return...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.