QUESTION IMAGE
Question
- (02.04 mc) which javascript code segment displays notebook after it is executed? (2 points) console.log(\keynote\.substr(3, 4) + \textbook\.substr(4, 4)); console.log(\keynote\.substr(2, 4) + \textbook\.substr(4, 4)); console.log(\keynote\.substr(4, 4) + \textbook\.substr(4, 4)); console.log(\keynote\.substr(3, 4) + \textbook\.substr(5, 4));
Step1: Recall substr function
The substr function in JavaScript takes two arguments: the starting index and the number of characters to extract.
Step2: Analyze first option
For console.log("keynote".substr(3, 4) + "textbook".substr(4, 4)):
"keynote".substr(3, 4)extracts "note" (starting at index 3, 4 characters)."textbook".substr(4, 4)extracts "book". The result is "notebook".
Step3: Analyze second option
For console.log("keynote".substr(2, 4) + "textbook".substr(4, 4)):
"keynote".substr(2, 4)extracts "ynot", result is "ynotbook".
Step4: Analyze third option
For console.log("keynote".substr(4, 4) + "textbook".substr(4, 4)):
"keynote".substr(4, 4)extracts "note" but starting at a different index than needed for "note" to combine right, result is not "notebook".
Step5: Analyze fourth option
For console.log("keynote".substr(3, 4) + "textbook".substr(5, 4)):
"textbook".substr(5, 4)extracts "tboo", result is "notetboo".
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
console.log("keynote".substr(3, 4) + "textbook".substr(4, 4));