Advertisement
karlakmkj

Mini challenge - spot the errors

Dec 7th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Mini challenge to correct all the errors
  2.  
  3. function useMagnifyingGlass():void{  //1. change from string to void - not return anything
  4.   console.log('I will use my magnifying glass.')
  5. }
  6.  
  7. function determineCulprit(){
  8.   return Math.floor(Math.random()*2+1)
  9. }
  10.  
  11. function doSleuthing(numberOfClues:number, clue1:string, clue2:string, suspect1, suspect2):void{ //2. Remove types for suspect1 & suspect2
  12.   console.log('I am a famous detective and I will solve the crime.');
  13.   let unnecessaryVariable = 'Why is this here?'
  14.  // unnecessaryVariable=useMagnifyingGlass();  // 3. Comment or remove this unnecessary line
  15.  
  16.   console.log('Now I consider the first clue: ',clue1);
  17.   console.log('Now I consider the second clue: ',clue2); //4. should be clue2 not clue1
  18.  
  19.   let culpritNumber:number = determineCulprit();  //5. Should be type number not string
  20.   console.log('Now, I will return to you the culprit. There but for the grace of God go we.' );
  21.   if(culpritNumber == 1) {return(suspect1)}
  22.   if(culpritNumber == 2) {return(suspect2)}
  23.  
  24.   console.log("I couldn't figure out who drank the priceless milk. :( :(")  //6. Change to console.log instead of return
  25. }
  26.  
  27. let answer; //7. remove =3;
  28.  
  29. //8. first argument should be number not '2'
  30. answer=doSleuthing(2, 'The parrot heard everything!', 'All the doors and windows were shut from the INSIDE.', 'Burglar Bob', 'Saint Sam')
  31.  
  32. console.log('The culprit was none other than ', answer, '!');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement