0

how can i use if else statement to find the minimum of a and b and assign it to variable min?

var a = 2000; var b = 1000; var min; if (a < b) { // TODO: assign min } else { // TODO: assign min } console.log("The minimum of a and b is: " + min);

23rd Jun 2017, 10:10 AM
Abdelghani Laaroussi
Abdelghani Laaroussi - avatar
3 Respuestas
+ 16
// Homework? var a = 2000; var b = 1000; var min; if (a < b) min = a; else min = b; console.log("The minimum of a and b is: " + min);
23rd Jun 2017, 10:16 AM
Maz
Maz - avatar
+ 4
// You can do it even shortener, using ternary operator ;) var a = 2000; var b = 1000; var min; min = (a < b) ? a : b; console.log("The minimum of a and b is: " + min);
23rd Jun 2017, 11:54 AM
visph
visph - avatar
0
thanks brother
23rd Jun 2017, 10:57 AM
Abdelghani Laaroussi
Abdelghani Laaroussi - avatar