Recap - Simple Calculator
Part of the Fundamentals section of Coddy's JavaScript journey — lesson 25 of 77.
Challenge
BeginnerYou are given a code that gets as input two numbers n1 and n2 and a character op (given).
The possible values for op are '+', '-', '/' and '*'
Your task is to set the variable result based on the conditions:
- if
opis'+', setresultwithn1 + n2. - if
opis'-', setresultwithn1 - n2. - if
opis'/', setresultwithn1 / n2. - if
opis'*', setresultwithn1 * n2.
Try it yourself
let n1 = parseInt(inp[0]) // Don't change this line
let n2 = parseInt(inp[1]) // Don't change this line
let op = inp[2] // Don't change this line
let result = 0
// Don't change the line below
console.log(`result = ${result}`)All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Type Coercion7Bill Split Calculator
Welcome MessageCalculating The Tip And Total2Variables
NumbersStringBooleanNaming ConventionsEmpty VariablesRecap - Initialize VariablesConstants3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsComparison OperatorsStrict vs Loose EqualityRecap - Simple Math6Basic IO
OutputOutput with VariablesType Conversion - Part 1Type Conversion - Part 2Recap - Till 120Recap - True or False