• +1 240 877 8161
  • info@thePracticalIT.com
Practical Information Technology
  • Notifi
  • Canvas
    • HOME
    • Start Here
    • Courses
    • EVENTS
      • EVENTS LIST
      • EVENTS GRID
    • BLOG
    • CONTACT
    • IT Courses
  • +1 240 877 8161
  • info@thePracticalIT.com
  • Profile
  • Login | Registration Popup Link
Practical Information Technology
  • Home
  • Courses
    • FEATURED COURSES
      • Web Development
      • Database Development
      • Business Intelligence
    • TRAINING
      • How long does it take?
      • IT Training Methods
      • Hours Per week
      • Payments
    • IT Courses
  • Tips
  • Contact
  • Notifi
  • Start Here

Counting Numbers Above 20

Homepage - Programming Exercises - Counting Numbers Above 20

Pract IT

by Practical IT
Posted on 25 May, 2021
in
Programming Exercises
0 Comment

For the following array containing numbers, count how many numbers are above 20.

let score = [12, 1, 103, 22, 41, 15, 90, 78, 22, 31]

What is expected

By going through this exercise, you will learn how to iterate through an array and using a conditional statement where you will be checking for each number to be greater than 20 or not.

Hint: You need a counter variable where you will be accumulating the total count. This variable will be incremented whenever you get a number that is above 20.

Show Answer

let above20 = 0;
let i = 0;
while ( i < score.length) {
    if (score[i] > 20) {
        above20 += 1; //same as above20++ or above20 = above20 + 1
    }
    i++; //same as i+=1 or i=i+1
}
console.log("There are " + above20 + " numbers which are above 20");

Tags: arrays conditionals counting example exercise for while
User Avatar
Article by Practical IT

Works at Practical IT. Passionate about Technologies, Business and News.

Previous Story
Convert For Loop to While loop
Next Story
Accept Numbers And Populate Array

Related Articles

healthy food in glass

10 Healthy Habits for IT Professional to Keep You on Top of Your Game

‍These 10 healthy habits helps boosting your health. If you’re...

Guess Number from 1 to 10

You are using going to use the following snippet of...

Leave your comment Cancel Reply

(will not be shared)

SearchLeave your keyword

Change your life through Information Technology career today. Thousands have done it – it is your turn now. All you need is a passion to change your life and provide better for yourself and your family. Practical IT takes the rest.

QUICK LINKS

  • Home
  • Courses
    • FEATURED COURSES
      • Web Development
      • Database Development
      • Business Intelligence
    • TRAINING
      • How long does it take?
      • IT Training Methods
      • Hours Per week
      • Payments
    • IT Courses
  • Tips
  • Contact
  • Notifi
  • Start Here

SUBSCRIBE EMAIL

Subscribe to our email list and get tips on IT jobs, career changes openings, seminars and more. We can also SMS you

GET IN TOUCH

You can call us, email us or even better visit us in our office at the heart of Silver Spring. Our Email - info@thePracticalIT.com

+1 240 877 8161

911 Silver Spring Ave #101 Silver Spring MD 20910

Practical IT - Copyright 2023.
  • Sign in

or
  • Login with Facebook
  • Login with Google

Forgot your password?

Lost your password? Please enter your email address. You will receive mail with link to set new password.

Back to login