0% found this document useful (0 votes)
4 views7 pages

JavaScript Logic Questions for Students

This is for javascript

Uploaded by

classicesteban86
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

JavaScript Logic Questions for Students

This is for javascript

Uploaded by

classicesteban86
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

JavaScript Logic Questions

Practice Quiz for Students

Question 1: Array Filtering


Write a function that takes an array of numbers and returns a new array containing only the even
numbers.

Example:

javascript

// Input: [1, 2, 3, 4, 5, 6, 7, 8]
// Expected Output: [2, 4, 6, 8]

Your Answer:

javascript

function filterEvenNumbers(arr) {
// Write your code here
}

Question 2: Conditional Logic


Create a function that determines a student's grade based on their score:

90-100: "A"
80-89: "B"

70-79: "C"
60-69: "D"
Below 60: "F"

Your Answer:

javascript

function getGrade(score) {
// Write your code here
}
Question 3: Array Manipulation
Write a function that finds the largest number in an array without using the Math.max() method.

Example:

javascript

// Input: [3, 7, 2, 9, 1, 5]
// Expected Output: 9

Your Answer:

javascript

function findLargest(arr) {
// Write your code here
}

Question 4: String and Array Logic


Create a function that takes a string and returns an array of words, but only includes words that are
longer than 3 characters.

Example:

javascript

// Input: "The quick brown fox jumps"


// Expected Output: ["quick", "brown", "jumps"]

Your Answer:

javascript

function filterLongWords(sentence) {
// Write your code here
}

Question 5: Nested Conditionals


Write a function that determines if a person can vote based on their age and citizenship status. The
person must be 18 or older AND be a citizen to vote.

Your Answer:
javascript

function canVote(age, isCitizen) {


// Write your code here
// Return true or false
}

Question 6: Array Search


Create a function that checks if a specific value exists in an array. Return the index if found, or -1 if not
found (similar to indexOf, but write your own logic).

Example:

javascript

// Input: ([10, 20, 30, 40], 30)


// Expected Output: 2

Your Answer:

javascript

function findIndex(arr, target) {


// Write your code here
}

Question 7: Multiple Conditions


Write a function that categorizes a person's life stage based on their age:

0-12: "Child"

13-17: "Teenager"

18-64: "Adult"
65+: "Senior"

Your Answer:

javascript

function getLifeStage(age) {
// Write your code here
}
Question 8: Array Transformation
Create a function that takes an array of temperatures in Celsius and returns a new array with
temperatures converted to Fahrenheit. Use the formula: F = (C × 9/5) + 32

Example:

javascript

// Input: [0, 20, 30, 100]


// Expected Output: [32, 68, 86, 212]

Your Answer:

javascript

function celsiusToFahrenheit(celsiusArray) {
// Write your code here
}

Question 9: Complex Logic


Write a function that determines if a year is a leap year. A leap year is divisible by 4, but if it's divisible
by 100, it must also be divisible by 400.

Examples:

2020: Leap year (divisible by 4)

1900: Not a leap year (divisible by 100 but not 400)

2000: Leap year (divisible by 400)

Your Answer:

javascript

function isLeapYear(year) {
// Write your code here
}

Question 10: Array and Conditional Challenge


Create a function that takes an array of student objects and returns an array containing only the names
of students who have a grade of 80 or higher.

Example:
javascript

const students = [
{name: "Alice", grade: 85},
{name: "Bob", grade: 72},
{name: "Charlie", grade: 90},
{name: "Diana", grade: 78}
];
// Expected Output: ["Alice", "Charlie"]

Your Answer:

javascript

function getHighAchievers(students) {
// Write your code here
}

Answer Key
Remove this section when distributing to students

Question 1:

javascript

function filterEvenNumbers(arr) {
return arr.filter(num => num % 2 === 0);
}

Question 2:

javascript

function getGrade(score) {
if (score >= 90) return "A";
else if (score >= 80) return "B";
else if (score >= 70) return "C";
else if (score >= 60) return "D";
else return "F";
}

Question 3:

javascript
function findLargest(arr) {
let largest = arr[0];
for (let i = 1; i < arr.length; i++) {
if (arr[i] > largest) {
largest = arr[i];
}
}
return largest;
}

Question 4:

javascript

function filterLongWords(sentence) {
return sentence.split(' ').filter(word => word.length > 3);
}

Question 5:

javascript

function canVote(age, isCitizen) {


return age >= 18 && isCitizen;
}

Question 6:

javascript

function findIndex(arr, target) {


for (let i = 0; i < arr.length; i++) {
if (arr[i] === target) {
return i;
}
}
return -1;
}

Question 7:

javascript
function getLifeStage(age) {
if (age <= 12) return "Child";
else if (age <= 17) return "Teenager";
else if (age <= 64) return "Adult";
else return "Senior";
}

Question 8:

javascript

function celsiusToFahrenheit(celsiusArray) {
return celsiusArray.map(celsius => (celsius * 9/5) + 32);
}

Question 9:

javascript

function isLeapYear(year) {
return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
}

Question 10:

javascript

function getHighAchievers(students) {
return students
.filter(student => student.grade >= 80)
.map(student => student.name);
}

Instructions for Students:

1. Read each question carefully


2. Write your code in the provided space

3. Test your solutions with the given examples

4. Make sure your functions handle edge cases

5. Use proper JavaScript syntax and formatting

Good luck!

You might also like