TalentJR apps
Textbook: Information Technology – Class 11 (Balbharati, official free PDF) · pages 85
Skill Set 3 lists four JavaScript practicals: number programs with prompt and if-else, more number checks, string functions, and event-driven programs with buttons. This page teaches the JavaScript you need, then gives a complete, tested program for every task in SOP 1 to SOP 4, with what the screen shows and the errors students usually make. Tags are shown in square brackets on this page: [script] means the script tag typed with angle brackets, [/script] its closing tag. JavaScript code itself is written exactly as you type it.
JavaScript runs inside the browser and adds logic to an HTML page. Code goes between [script] and [/script] in the head or body. prompt() reads input as text, parseInt() or parseFloat() turns that text into a number, alert() or document.write() shows the result, and if / else if / else chooses what to do.
SOP 1 and SOP 2 are number programs: multiply by 3, find the larger of two numbers, decide positive, negative or zero, test two numbers for equality, find a square, and check for multiples of 3 or 7 with the remainder operator %.
SOP 3 uses strings: the length property counts characters, toLowerCase() and toUpperCase() change case, and comparing length with 4 decides whether the string has at least 4 characters.
SOP 4 is event-driven: a function runs only when a button is clicked (onClick). It reads text boxes through the form (form1.t1.value), uses isNaN() to check whether an entry is a number, and calculates addition and division of two numbers, guarding against division by zero.
Good habits: declare variables with var (or let), convert input before doing maths, use == or === to compare and = only to assign, end statements with semicolons, and open the browser console (F12) to see errors.
Get a ✓ Verified tutor for “Skill Set 3 – Client Side Scripting (JavaScript)” — live online or at home. We aim to suggest up to 3 tutors within 24 hours.
Write the script for all three tasks of SOP 1.
Answer: var n = parseInt(prompt('Enter an integer')); document.write('3 x ' + n + ' = ' + (n * 3) + '[br]'); var a = parseInt(prompt('First integer')); var b = parseInt(prompt('Second integer')); if (a > b) document.write(a + ' is larger[br]'); else if (b > a) document.write(b + ' is larger[br]'); else document.write('Both are equal[br]'); var m = parseInt(prompt('Enter a number')); if (m > 0) alert(m + ' is positive'); else if (m < 0) alert(m + ' is negative'); else alert('The number is zero'); — Input 7 shows '3 x 7 = 21'. (In real code, [br] is the br tag.)
Write the multiple-of-3-or-7 check so that 21, 9, 14 and 10 each get the right message.
Answer: var n = parseInt(prompt('Enter an integer')); if (n % 3 == 0 && n % 7 == 0) alert(n + ' is a multiple of both 3 and 7'); else if (n % 3 == 0) alert(n + ' is a multiple of 3'); else if (n % 7 == 0) alert(n + ' is a multiple of 7'); else alert(n + ' is a multiple of neither 3 nor 7'); — 21 → both, 9 → 3, 14 → 7, 10 → neither.
Write SOP 3 as one script.
Answer: var s = prompt('Enter a string'); document.write('Length: ' + s.length + '[br]'); document.write('Lowercase: ' + s.toLowerCase() + '[br]'); document.write('Uppercase: ' + s.toUpperCase() + '[br]'); if (s.length >= 4) document.write('The length is 4 or greater'); else document.write('The length is less than 4'); — For 'Pune': Length 4, pune, PUNE, 'The length is 4 or greater'.
Write the complete page for the addition and division part of SOP 4 (inputs 12 and 10).
Answer: [head][script] function add() { var a = parseFloat(form1.t1.value); var b = parseFloat(form1.t2.value); form1.t3.value = a + b; } function divide() { var a = parseFloat(form1.t1.value); var b = parseFloat(form1.t2.value); if (b == 0) form1.t3.value = 'Cannot divide by zero'; else form1.t3.value = a / b; } [/script][/head] [body][form name='form1'] 1st Number: [input type='text' name='t1'][br] 2nd Number: [input type='text' name='t2'][br] [input type='button' value='Addition' onClick='add()'] [input type='button' value='Divide' onClick='divide()'][br] Result: [input type='text' name='t3'] [/form][/body] — With 12 and 10: Addition → 22, Divide → 1.2.
| Statement / function | What it does | Example |
|---|---|---|
| prompt() | Reads input as text | var a = prompt('Enter a number'); |
| parseInt() / parseFloat() | Text → whole / decimal number | parseInt('42') gives 42 |
| alert() | Message box with OK | alert('Number is even'); |
| document.write() | Writes onto the page | document.write('Square = ' + n * n); |
| if … else if … else | Chooses one of several blocks | if (n > 0) … else if (n < 0) … else … |
| % | Remainder after division | 21 % 7 gives 0 |
| && / || | Both true / at least one true | n % 3 == 0 && n % 7 == 0 |
| str.length | Number of characters | 'India'.length gives 5 |
| toUpperCase() / toLowerCase() | Change case | 'Pune'.toUpperCase() gives PUNE |
| isNaN() | true if not a number | isNaN('12a') gives true |
| onClick | Runs a function on a click | [input type='button' value='Check' onClick='check()'] |
Solve each one in your notebook first. Then open the solution and compare every step.
1. SOP 1: (a) accept an integer and show it multiplied by 3; (b) accept two integers and show the larger; (c) check whether a number is positive or negative.
Answer: Sample: see the SOP 1 example in the notes for the full code. Test cases: (a) 7 → 21, −4 → −12. (b) 15 and 9 → '15 is larger'; 6 and 6 → 'Both are equal'. (c) 8 → positive; −3 → negative; 0 → zero. Steps: type in an editor → save sop1.html → open in browser → enter the test values → note outputs in the journal.
2. SOP 2: (a) read two numbers (either sign) and test whether they are equal; (b) accept a number and show its square; (c) check whether an integer is a multiple of 3 or of 7.
Answer: Sample: (a) var a = parseFloat(prompt('First number')); var b = parseFloat(prompt('Second number')); if (a == b) alert('Both numbers are equal'); else alert('Numbers are not equal'); (b) var n = parseFloat(prompt('Enter a number')); alert('Square of ' + n + ' is ' + (n * n)); (c) the multiple-of-3-or-7 example in the notes. Tests: −5 and −5 → equal; 4 and −4 → not equal; −6 → 36; 2.5 → 6.25; 21 → both; 9 → 3; 14 → 7; 10 → neither.
3. SOP 3: accept a string and (a) find its length, (b) display it in lowercase and uppercase, (c) check whether its length is 4 or more.
Answer: Sample: var s = prompt('Enter a string'); document.write('Length = ' + s.length + '[br]'); document.write('Lowercase = ' + s.toLowerCase() + '[br]'); document.write('Uppercase = ' + s.toUpperCase() + '[br]'); if (s.length >= 4) document.write('Length is 4 or greater'); else document.write('Length is less than 4'); ([br] is the br tag.) Tests: 'India' → 5, india, INDIA, 4 or greater; 'IT' → 2, it, IT, less than 4.
4. SOP 4 (a): with a text box and a Check button, validate whether the entered value is a number.
Answer: Sample: [head][script] function check() { var v = form1.t1.value; if (v == '' ) alert('Please enter a value'); else if (isNaN(v)) alert(v + ' is not a number'); else alert(v + ' is a number'); } [/script][/head] [body][form name='form1'] Enter Value: [input type='text' name='t1'] [input type='button' value='Check' onClick='check()'] [/form][/body]. Tests: 45 → is a number; 4.5 → is a number; 45ab → is not a number; empty → please enter a value.
5. SOP 4 (b): with two text boxes and Addition and Divide buttons, calculate the sum and quotient (e.g. 12 and 10).
Answer: Sample: the full page is in the SOP 4 example in the notes. Output for 12 and 10: Addition → 22, Divide → 1.2. For 12 and 0: Divide → 'Cannot divide by zero'. Without parseFloat, Addition would show 1210 because the box values are strings.
6. Find the errors: var n = prompt('Enter number') ; if (n % 2 = 0) alert('Even') else alert('Odd'); var s = 'Pune'; alert(s.length());
Answer: (1) n should be converted: var n = parseInt(prompt('Enter number')); (it works by automatic conversion for %, but conversion is the correct habit). (2) n % 2 = 0 tries to assign and gives 'Invalid left-hand side in assignment' — use == (or ===): if (n % 2 == 0). (3) With else on the same line, alert('Even') must end with a semicolon, otherwise the browser reports 'Unexpected token else' — write if (n % 2 == 0) alert('Even'); else alert('Odd'); (4) length is a property: s.length, not s.length() — the brackets cause a TypeError. Correct output for 'Pune' is 4.
Read the question, answer it in your head, then tap the card to check. 20 cards.
15 questions. Tap an option — you will see at once if it is right and why.
1. JavaScript code in a page is placed inside the…
Answer: B. In head or body.
2. prompt() returns the user's entry as a…
Answer: C. Convert it before maths.
3. If a = '4' and b = '5', a + b gives…
Answer: B. Strings are joined.
4. Which converts '7.5' to 7.5?
Answer: C. parseInt would give 7.
5. Which condition checks that n is negative?
Answer: C. Less than zero.
6. Which condition tests a multiple of 7?
Answer: B. Remainder zero.
7. 21 is a multiple of…
Answer: B. 21 = 3 × 7.
8. The square of n is…
Answer: B. Or Math.pow(n, 2).
9. 'Nashik'.length is…
Answer: C. Six characters.
10. 'Pune'.toLowerCase() gives…
Answer: A. All small letters.
11. Which shows a message box with only an OK button?
Answer: C. confirm has OK and Cancel.
12. isNaN('25b') returns…
Answer: D. '25b' is not a valid number.
13. A function runs on a button click when the button has…
Answer: A. Event handler attribute.
14. With 12 and 10, division gives…
Answer: A. 12 / 10 = 1.2.
15. To avoid showing Infinity, before dividing you check…
Answer: D. x / 0 is Infinity.
Get a ✓ Verified tutor for “Skill Set 3 – Client Side Scripting (JavaScript)” — live online or at home. We aim to suggest up to 3 tutors within 24 hours.
Done with the notes? Revise Skill Set 3 – Client Side Scripting (JavaScript) the fun way: match key terms, beat the 60-second lightning round and spot true or false facts. Every game uses only this lesson, so each round is real exam revision.
⭐ 0 XP⏱ About 35 minutes (plus lab time)
Get a ✓ Verified tutor for “Skill Set 3 – Client Side Scripting (JavaScript)” — live online or at home. We aim to suggest up to 3 tutors within 24 hours.
Sign in free to see the answers to the textbook exercise of Skill Set 3 – Client Side Scripting (JavaScript).
Sign in to see solutionsStuck on a question? Type it, 🎤 speak it or 📷 snap a photo of it and get simple, step-by-step help with “Skill Set 3 Client Side Scripting (JavaScript)” — important questions, a quick quiz, revision notes — in English, मराठी or हिंदी.
Sign in with Google to ask the AI tutor. It's free — 20 questions a day, one TalentJR account.
Sign in to askPrefer a real teacher? TalentJR teachers take live online classes anywhere in India. Tell us what you need and our team will call you with timings and fees.