Javascript part 10

Jonathan Bleibdrey
4 min readFeb 8, 2021

--

Today we will talk about 8 different “Math.” functions in javascript and the “ parseInt” method, Falalala-lala-la.

OK, Most of these require “Math” in front of them, so if you don't see them There just assume Math comes before it. Here we go!

.random(): Here we are using the Math method followed by .random(). All this does is generates a random number. To be even more specific, it will generate numbers more than 0 but less than 1.

.floor() : this will always round a decimal down (hint, the floor =’s down).

Say you wanted a random number between 0–19 you would multiply it by twenty and then run, Math.floor() which then rounds it down. (It won't land on 20 because it always rounds down.)

I've also done a range between 0–99 just so you know that, whatever you multiply it by, you get all the numbers right below the number you put, and 0. (it will never land on the “100"! because it always rounds down, thus never landing on 100.)

.round() : this will return a value rounded to its nearest integer. I put a decimal at 3.6 and 3.4 to show you that it will round up or down to the nearest whole number in either direction.

.pow() : this takes in two arguments one being the number to multiply with and the second is how many times to multiply itself by.

Here we see that the first argument in “.pow” is the main number, then the second number is how many times we are going to multiple that first number by. (so Math.pow(2,6) its the same as saying this: 2*2*2*2*2*2 = 64)

.abs() : this will give you the absolute value of a number (Basically just give you a whole number if it's negative.) if you see below, it changes all negative inputs into positives.

.ceil() : this will round up to the the nearest whole number(aka: ceiling = up). see no matter what, it will always round up from any range to the nearest number.

.min() : this will look through an array of numbers and return the LOWEST number. (It looks through the numbers and finds the minimum) Plain and simple!

.max() : this will look through an array of numbers and return the HIGHEST number. (It looks through the numbers and finds the maximum.)

parseInt:

.parseInt() : this will take any string and convert it to a number. here we use it on “007” and it made it a solid 7 number. If you were to use this on a word it would give you. “NaN” is not a number, And the last part is a simple number in a form of a string and turned into a “real number”.

well, that's enough math for one day!

See you all next time

check out some javascript….

Javascript 1 (variables and data types)

Javascript 2 (numbers and strings)

Javascript 3 (bracket notation and 20 diff string methods)

Javascript 4 (functions and how they work)

Javascript 5 (hoisting, comparison operators, and if-else statements)

Javascript 6 (diff. Equal signs, null, and undefined)

Javascript 7 (logical operator, &&, || and ternary operators)

Javascript 8 (switch statements and arrays)

Javascript 9 (10 commonly used arrays in javascript)

Javascript 10 (8 different Math. methods And parseInt Usage)

Javascript 11 (for loops and nested for loops)

Javascript 12(while loops and for..in and for..of loops)

Javascript 13(8 diff array methods)

Javascript 14(objects and ways to use objects)

Javascript 15(JSON and fetch request)

Javascript 16(“this” keyword)

Javascript 17(strict mode and error handling)

Javascript 18(setInterval/setTimeout and Dates)

React info…

React part 1 (How to start a react app)

React part 2 (components and dynamic values)

React part 3 (Multiple components and small styling)

React part 4 (click events with functions and react dev tools)

React part 5 (link to: useState hook and how to output lists in react)

React part 6 (Props and reusable components)

React part 7 (passing functions as props and use effect hook)

React part 8 (continue with useEffect hook, dependencies with useEffect, and setting up the JSON server to fetch)

React part 9 (Fetching data with JSON)

React part 10 (loading bar and fetch errors)

React part 11(custom hooks)

React part 12(React Router Dom, Exact, and Links)

The Social Media…

Github

Instagram

Facebook

Linked-In

Medium

--

--

Jonathan Bleibdrey
Jonathan Bleibdrey

Written by Jonathan Bleibdrey

Software engineer, Creator, Ball of Energy

No responses yet