JavaScript · Lesson 17 / 32 · தமிழ்
JavaScript Math
கருத்தைப் புரிந்துகொள்ளுங்கள். Code-ஐ மாற்றி இயக்குங்கள். ஒரு சிறிய பயிற்சியால் கற்றதை உறுதி செய்யுங்கள்.
மூலப் பாட விளக்கங்கள் தமிழில் உள்ளன. கூடுதல் concept, practice மற்றும் answer notes ஆங்கிலத்தில் உள்ளன.
முக்கியக் கருத்து
Math provides static numeric utilities. Pick the rounding rule that matches the requirement: floor, ceil, round, and trunc are not interchangeable.
Learning goal: Explain what the example does, predict its result, and change it to solve the practice task.
விரிவான விளக்கங்கள்
Math Object
Math object mathematical constants மற்றும் functions provide பண்றது. இது constructor இல்ல — எல்லா properties மற்றும் methods-உம் static.
Math.PI; // 3.141592653589793
Math.E; // 2.718281828459045
// Rounding
Math.round(4.5); // 5
Math.ceil(4.1); // 5
Math.floor(4.9); // 4
Math.trunc(4.9); // 4
// Power & Root
Math.pow(2, 8); // 256
Math.sqrt(16); // 4
// Min / Max
Math.min(1, 2, 3); // 1
Math.max(1, 2, 3); // 3
Math.min(...[5, 2, 8, 1]); // 1 (spread use பண்ணு)Random Numbers
// Math.random() → [0, 1) — 1 தவிர
Math.random();
// min மற்றும் max-க்கு இடையே random integer
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
console.log(randomInt(1, 6)); // dice roll: 1-6
// Array-ல random element
const items = ["rock", "paper", "scissors"];
const pick = items[randomInt(0, items.length - 1)];முழுமையான உதாரணம்
Run this complete index.js program in the JavaScript console editor below. The earlier reference fragments may need a browser page or other surrounding setup.
const score = 7.6;
console.log(Math.floor(score));
console.log(Math.ceil(score));
console.log(Math.round(score));
console.log(Math.max(12, 28, 19));எதிர்பார்க்கும் முடிவைப் பாருங்கள்
7 8 8 28
மாற்றி இயக்கிப் பாருங்கள்
Load the example, change a value, predict the output, and run it again. Use the console output to check your reasoning.
Editor load ஆனதும் code-ஐ ஏற்றி Run அழுத்துங்கள்.
OneCompiler என்ற இலவச வெளிப்புற சேவை code-ஐ இயக்குகிறது. Run செய்யும் code அங்கு அனுப்பப்படும். தனிப்பட்ட தகவல்கள் அல்லது secret keys உள்ளிட வேண்டாம்.
சிறிய பயிற்சி
Practice challenge
Change score to -7.6 and compare floor with trunc.
விடை மற்றும் விளக்கம்
Math.floor(-7.6) is -8; Math.trunc(-7.6) is -7.
தவிர்க்க வேண்டிய தவறு: Math.random is not suitable for passwords or security tokens. Use a cryptographically secure API for security requirements.
அடுத்த பாடத்திற்குத் தயாரா?
- Explain the example in your own words.
- Complete the challenge before revealing its answer.
- Describe the common mistake and how to avoid it.