Take as many assements as you can to improve your validate your skill rating
Total Questions: 20
1. What is the output of given code?
counter=1
if counter<=5
puts (counter)
counter=counter+1
else
puts(counter)
counter=counter-1
end
Correct Answer is : 1
2. What is the output of given code?
#counter=1
if counter<=5
puts (counter)
counter=counter+1
else
puts(counter)
counter=counter-1
end
Correct Answer is : Undefined local variable counter
3. It is necessary that always if should come with else block?
Correct Answer is : FALSE
4. Which of the following is valid conditional statement in Ruby?
Correct Answer is : elsif
5. The elsif conditional statement is written with an expression.
Correct Answer is : TRUE
6. The elsif statement can add many alternatives to if/else statements.
Correct Answer is : TRUE
7. What is the output of the given code?
counter=6
if counter<=5
puts (counter)
counter=counter+1
puts (counter)
elsif counter>5
puts (counter)
counter=2*counter
puts(counter)
else
puts(counter)
counter=counter-1
puts(counter)
end
Correct Answer is : 6
8. What is output of the given code?
counter=-3
if counter<=5
puts (counter)
counter=counter+1
puts (counter)
elsif counter>5
puts (counter)
counter=2*counter
puts(counter)
end
Correct Answer is : -3
9. What is the output of the given code?
if !true
print "False"
elsif !true || true
print "True"
end
Correct Answer is : TRUE
10. What is the output of the given code?
variable = false
if variable
print "false"
elsif !variable
print "true"
end
Correct Answer is : TRUE
11. What is the output of the given code?
x=7
y=9
if x==y
print "equal"
elsif x>y
print "greater"
else
print "less"
end
Correct Answer is : less
12. What is the output of the given code?
a=10
b=2
if a>b
a=a*b
puts (a)
elsif a
Correct Answer is : 20
13. The following syntax is correct for if conditional statement.
if condition
code
end
Correct Answer is : TRUE
14. If expression.
The expression can be of which type?
Correct Answer is : All of the mentioned
15. What error does the if condition gives if not terminated with end statement?
Correct Answer is : All of the mentioned
16. What is the output of the following?
if 1<2
print "one is less than two"
end
Correct Answer is : One is less than two
17. What is the output of the code?
if 11<2
print "Eleven is less than two"
end
print "11 is greater"
Correct Answer is : 11 is greater
18. What is the output of the given code?
if 11>2
puts "Eleven is greater than two"
end
print "You'r right"
Correct Answer is : Eleven is greater than two
19. What is the output of the given code?
if 79>78
puts "True".upcase
if 9>8
puts "True".reverse
if 7==7
puts "equal".downcase
end
end
end
Correct Answer is : TRUE
20. What is the output of the given code?
if 79>78
puts "True".upcase
if 9>8
puts "True".Upcase
if 7==7
puts "equal".downcase
end
end
end