usingMaths.com
From Theory to Practice - Math You Can Use.







<< PreviousNext >>

How to Generate Odd Numbers in JavaScript for Kids




What are Odd Numbers? | Maths Explanation for JavaScript Kids

Odd numbers are numbers that are not divisible by 2.

They include:

1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, ...

In this beginner-friendly Maths JavaScript tutorial for kids, we'll explore how to list odd numbers using JavaScript loops and conditions — perfect for primary school students learning to code.
To generate odd numbers in JavaScript, we use a 'while' loop combined with a conditional statement. This simple JavaScript exercise will help you understand number patterns and logic.

Create a new file; On Notepad++: File, New.
Call it OddNumbers.html.
Type out the adjoining JavaScript code for listing odd numbers.




Code for Odd Number List with User Input in JavaScript

For a little more flexibility, let's add an input form.



We have used a function here.
A function is a chunk of code that is executed when it is called upon, such as when an event occurs.



So! JavaScript Fun Practice Exercise - List Odd Numbers

As a fun practice exercise, feel free to try out your own boundary values, and see how the JavaScript code lists the odd numbers between those boundary values.









<< PreviousNext >>