JavaScript bootcamp · Lab 02

Sum two numbers

easyInput8 minLesson: Variables

Read the question, write JavaScript on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

These labs give you a readLine() helper that returns the next line of input as a string.

Read two integers (one per line) and log their sum. Convert each line with Number() first — otherwise "3" + "5" concatenates into "35".

Input. Two lines, each an integer.

Output. One integer: a + b

Constraints

  • -1000000 ≤ a, b ≤ 1000000

Examples

Example 1
Input
3
5
Output
8
Example 2 — Negatives included.
Input
10
-4
Output
6
Hint
  1. Number(readLine()) turns a line into a number.
  2. Log a + b, not a concatenated string.
Show correct code

Peek only after you have tried. You can still Check your own version.

const a = Number(readLine());
const b = Number(readLine());
console.log(a + b);
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.